PNG as Form background

  • Thread starter Thread starter =?ISO-8859-1?Q?Ga=EBl_Rosset?=
  • Start date Start date
?

=?ISO-8859-1?Q?Ga=EBl_Rosset?=

Hi,

Do you know how to enable the use of a PNG as a form background and
hence enable per pixel alpha transparency ?

I have found some code on the code project but it either does not work
with Visual Studio 2005 (the form editor stops working because I need to
inherit from a Form derivate) or I get a completely transparent application.

Thanks for the help.
 
If you want to draw a PNG to the background of the form, but allow the
form's backcolor to "shine through" the semi-transparent pixels in the PNG,
you must set the form's BackgroundImage to null, and draw the image
manually. You can do this by overriding the form's OnPaint method and using
the supplied Graphics object to draw the image. The image can be stored in
your resources.

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(My.Resources.ImageResourceName, 0, 0)
MyBase.OnPaint(e)
End Sub

Hope this helps,
Andrew
 
Back
Top