Thanks Sergey, Could you take a look at my code for me? I tried
creating a new project named transparency from scratch and it crashes
if I run it. Crash is a 'Stackoverflowexception in default domain'
'My Form1 code (form1 is where I'd want the transparent picturebox):
Imports transparency.PictureboxEX.ControlCollection
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox
'
'PictureBox1
'
Dim pb As PictureboxEX = New PictureboxEX
pb.Location = New System.Drawing.Point(0, 0)
pb.Size = New System.Drawing.Size(240, 240)
Me.PictureBox1.Location = New System.Drawing.Point(56, 88)
Me.Picturebox1.Controls.Add(pb)
'
'Form1
'
Me.ClientSize = New System.Drawing.Size(242, 272)
Me.Controls.Add(Me.PictureBox1)
Me.Text = "Form1"
End Sub
'My PictureboxEX class code:
Imports System.Drawing.Imaging.ImageAttributes
Public Class PictureboxEX
Inherits System.Windows.Forms.PictureBox
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim attr As Imaging.ImageAttributes = New
Imaging.ImageAttributes
attr.SetColorKey(Color.FromArgb(255, 0, 255),
Color.FromArgb(255, 0, 255))
e.Graphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0,
Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
End Sub
End Class