1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Häufig gestellte Fragen

Erstellen transparenter Steuerelemente mit Mausereignisbehandlung

Erstellen transparenter Steuerelemente mit Mausereignisbehandlung

Creating transparent controls that can handle mouse events

The class 'TransparentControl' provides a control that is fully transparent
without loosing the ability to handle the control's events.  This is
achieved by adjusting the control's extended style bits:

Imports System
Imports System.Windows.Forms

Public Class TransparentControl
    Inherits Control

    Private Const WS_EX_TRANSPARENT As Int32 = &H20

    Public Sub New()
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.BackColor = Color.Transparent
    End Sub

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARENT
            Return cp
        End Get
    End Property

    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
    End Sub
End Class