Scroll To Top
Reader Level:
GDI+ & Graphics

Making Transparent Controls using GDI+ and C#

By nildo on May 14, 2003
This article shows you how to draw transparent controls with the help of GDI+.

This article provides an approach to a Transparent Control that draws an ellipse with real transparent background and a brush that supports transparent colors.

Below sample project is included in the ZIP file. In addition, you will find a file that contains the control TranspControl.ddl. It was made and based on technique presented in this article.

To make a transparent control you may create a default control and proceed with the following steps:

1. Add the transparent style to the control window.

Protected override CreateParams CreateParams
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;

2. Override the OnPaintBackground event. This is necessary to prevent the background to be painted.

Protected override void OnPaintBackground(PaintEventArgs e)
// do nothing

3. Override the OnMove event with the following code.

Protected override void OnMove(EventArgs e)