Transparent background with multiple controls.

I am trying to create an application in which a user can move three shortcuts with a transparent background. If one label is located above another, the second should be visible. For this, I created a user control because I want the user shortcut to have a transparent background →, and therefore I set SupportsTransparentBackColors and UserPaint via SetStyle ()

Public Class Customlabel
    Inherits System.Windows.Forms.Control

    Public Sub New()
        MyBase.New()
        Me.SetStyle(Windows.Forms.ControlStyles.UserPaint, True)
        Me.SetStyle(Windows.Forms.ControlStyles.DoubleBuffer, True)
        Me.SetStyle(Windows.Forms.ControlStyles.SupportsTransparentBackColor, True)
        InitializeComponents()
    End Sub

    Private Sub InitializeComponents()
        Me.Width = 100
        Me.Height = 100
    End Sub

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.DrawString("Test", New System.Drawing.Font("Arial", 12), New System.Drawing.SolidBrush(Color.Black), New System.Drawing.Point(0, 0))
    End Sub
End Class

In the main form, I created shortcuts, as you could see:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim AB As Customlabel = New Customlabel
        AB.Left = 20
        AB.Top = 20
        AB.Name = "one"
        Me.Controls.Add(AB)

        Dim AC As Customlabel = New Customlabel
        AC.Left = 50
        AC.Top = 20
        AC.Name = "two"
        Me.Controls.Add(AC)

        Dim AD As Customlabel = New Customlabel
        AD.Left = 70
        AD.Top = 20
        AD.Name = "three"
        Me.Controls.Add(AD)
    End Sub

End Class

Despite the fact that the labels are drawn as a rectangle without a transparent background, and the overlapping CustomLabel is not visible. If I set the parent property of the labels in the form, the background is transparent only with respect to the Form. (not to other CustomLabels)

Anyone have an idea how to solve this problem?

+4
2

, . . .png .gif .. . . , . .

0

,

- :

:

Me.TransparencyKey = BackColor

:

Me.TransparencyKey = Transparent
-1

Source: https://habr.com/ru/post/1533789/


All Articles