This is a customized PictureBox with a "real" transparent Background.
Public Class customPictureBox
Inherits PictureBox
Public Sub New()
Me.SetStyle(ControlStyles.Opaque, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaint(pe As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
If MyBase.BackgroundImage IsNot Nothing Then
pe.Graphics.DrawImage(MyBase.BackgroundImage, 0, 0)
End If
End Sub
End Class
Unfortunately, because of overiding the OnPaint-method, all wanted painting work now must be done by yourself - this includes the painting of the image. In my example I draw the image in it's original size - but certainly it is possible to do also scaling (resizing) and so on - but now manually ... :(