I am trying to create a picturebox that respects the transparency
setting of png files. This works when the parent is a panel without
borders. What fix do I need to get it to work on forms or panels with
borders without it having a misalignment issue?
What I am doing is getting what is under my picturebox from my parent
before calling MyBase.OnPaint.
Public Class TransparentPictureBox
Inherits PictureBox
Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = pe.Graphics
Dim bmp As New Bitmap(Parent.Width, Parent.Height)
Parent.DrawToBitmap(bmp, New Rectangle(0, 0, Parent.Width,
Parent.Height))
g.DrawImage(bmp, 0, 0, New Rectangle(Left, Top, Width, Width),
GraphicsUnit.Pixel)
MyBase.OnPaint(pe)
End Sub
End Class