Public partial class tspControl: UserControl
{
Public tspControl ()
{
InitializeComponent ();
SetStyle (ControlStyles. SupportsTransparentBackColor
| ControlStyles. UserPaint
| ControlStyles. AllPaintingInWmPaint
| ControlStyles. Opaque, true );
This. BackColor = Color. Transparent;
}
Private Image img;
Public Image
{
Get
{
Return img;
}
Set
{
Img = value;
}
}
Protected override void OnLocationChanged (EventArgs e)
{
// Base. OnLocationChanged (e );
Visible = false;
Visible = true;
}
Protected override CreateParams
{
Get
{
// Return base. CreateParams;
CreateParams cp = base. CreateParams;
Cp. ExStyle | = 0x00000020; // WS_EX_TRANSPARENT
Return cp;
}
}
Protected override void OnPaint (PaintEventArgs pe)
{
If (img! = Null)
{
Base. OnPaint (pe );
Pe. Graphics. DrawImage (img, 0, 0 );
}
Else
{
}
}
}
// Note: If you manually change the image, you 'd better Refresh the page (this. Refresh ();) and remember that the image can be transparent only when it is transparent.