Custom Control with Transparent Background

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



/*
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. When the background of the controls iis transparent, both circles
will show.

If this feature is not available or only through some kind of hack, what is
the reason that Microsoft does not support controls with transparent
background?
*/


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;

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

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



//class MyForm
class MyForm:Form
{

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

//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new MyForm());
}
}



.



Relevant Pages

  • Re: graduated circles
    ... be a bunch of concentric graduated circles with a transparent cursor ... So I need to make graduated circles with the divisions in various ... see how far each one deviates from this as they are overlaid with each ...
    (rec.music.theory)
  • Transparent colors, newby question
    ... I have a picturebox with many rectangles and circles. ... some of them transparent. ...
    (microsoft.public.dotnet.framework.drawing)
  • Whats wrong with transparency by GD?
    ... I'm still unable to obtain 2 transparent ... circles. ... Could anybody tell me what's wrong in the following codes? ... binmode IMG; ...
    (comp.lang.perl.misc)
  • Re: Filled polygons print to PDF as opaque
    ... I cross posted this question to the Adobe Acrobat Windows users forum. ... transparent patterns) and the PDF driver uses PostScript to do the heavy ... your implication is that I'm stuck with a bitmap if I want ... Brush m_BG = new SolidBrush; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: How to make a paint brush tool with feathered edges
    ... The path gradient wil blend solid color to transparent color in a circle. ... Similar to this tool in Photoshop I want to have ... > 'feathered' edges so that the edge of the brush blends gradually with the ... > 1) How do I create the feather ability of such a tool. ...
    (microsoft.public.dotnet.framework.drawing)