469,931 Members | 2,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,931 developers. It's quick & easy.

Custom Control With Transparent Background

How can I give my custom System.Windows.Forms.Control a transparent
background? In the small application below I expect to see two partially
overlapping circles, a blue one and a red one, but only the blue circle
appears.

What more can I do to make the background truly transparent?

using System.Drawing;
using System.Windows.Forms;

//class ColorCircleControl
class ColorCircleControl:Control
{

//data member brush
Brush brush;

//data members x,y
int x;
int y;

//data member width
int width;

//constructor
public ColorCircleControl(Brush a,int b,int c,int d)
{
brush=a;
x=b;
y=c;
width=d;
SetStyle(ControlStyles.SupportsTransparentBackColo r,true);
BackColor=Color.Transparent;
Dock=DockStyle.Fill;
Paint+=OnPaint;
}

//OnPaint
void OnPaint(object a,PaintEventArgs b)
{
b.Graphics.FillEllipse(brush,x,y,width,width);
}
}

//class MyForm
class MyForm:Form
{

//constructor
public MyForm()
{
Controls.Add(new ColorCircleControl(Brushes.Blue,55,89,89));
Controls.Add(new ColorCircleControl(Brushes.Red,144,89,55));
ClientSize=new System.Drawing.Size(597,370);
}

//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new MyForm());
}
}
Sep 13 '06 #1
0 1294

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Steve | last post: by
1 post views Thread by Efkas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.