' The .NET Compact Framework supports transparency,
' but with only one transparency color.
' The SetColorKey method must have the same color
' specified for the low color and high color range.
' Note that you must uncomment lines of code
' as indicated for the desired transparency effect.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
' Create a red and black bitmap to demonstrate transparency.
Dim bmp As New Bitmap(75, 75)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillEllipse(New SolidBrush(Color.Red), 0, 0, bmp.Width, bmp.Width)
g.DrawLine(New Pen(Color.Black), 0, 0, bmp.Width, bmp.Width)
g.DrawLine(New Pen(Color.Black), bmp.Width, 0, 0, bmp.Width)
g.Dispose()
Dim attr As New ImageAttributes
' Set the transparency color key based on the upper-left pixel
' of the image.
' Uncomment the following line to make all black pixels transparent:
' attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0))
' Set the transparency color key based on a specified value.
' Uncomment the following line to make all red pixels transparent:
' attr.SetColorKey(Color.Red, Color.Red)
' Draw the image using the image attributes.
Dim dstRect As New Rectangle(0, 0, bmp.Width, bmp.Height)
e.Graphics.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height, _
GraphicsUnit.Pixel, attr)
End Sub