Hi All,

I have created a control that inherits from RadioButton and I have
overridden it's OnPaint method. It looks great, draws the background
with every color except with Color.Transparent. When I make the
controls Background color transparent, it draws it black! Is there
anyway to fix this?

Inside the OnPaint method, my first line is:
e.Graphics.Clear(Color.BackColor);

I have also set the control style SupportsTransparentBackColor to true.

Any help would be greatly appreciated.

Thanks!

RE: Custom Radio Button with Transparent Background by swashi

swashi
Tue Aug 16 05:51:05 CDT 2005

Hi,
To change the controls background color to transparent you need not set
ControlStyle SupportsTransparentBackColor to true . Moreover,
inside the OnPaint method, e.Graphics.Clear(Color.BackColor); is also not
required
you can instead write

base.OnPaint(pevent); in your OnPaint method and it will work fine.


I have tried the following code and it works fine for me


public class rb : RadioButton
{

protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);

}
}


private void Form1_Load(object sender, EventArgs e)
{
rb r1 = new rb();
r1.BackColor = Color.Transparent;
this.Controls.Add(r1);

}




"joshuaphillips@comcast.net" wrote:

> Hi All,
>
> I have created a control that inherits from RadioButton and I have
> overridden it's OnPaint method. It looks great, draws the background
> with every color except with Color.Transparent. When I make the
> controls Background color transparent, it draws it black! Is there
> anyway to fix this?
>
> Inside the OnPaint method, my first line is:
> e.Graphics.Clear(Color.BackColor);
>
> I have also set the control style SupportsTransparentBackColor to true.
>
> Any help would be greatly appreciated.
>
> Thanks!
>
>

Re: Custom Radio Button with Transparent Background by joshuaphillips

joshuaphillips
Tue Aug 16 13:37:38 CDT 2005

Thanks Swashi,

Unfortunately this doesn't work for me. The whole reason I created a
custom radio button was to be able to override its OnPaint method, and
paint and image instead of the standard circle. I wonder what the code
MS uses that paints transparency. I'll keep looking...

Josh

swashi wrote:
> Hi,
> To change the controls background color to transparent you need not set
> ControlStyle SupportsTransparentBackColor to true . Moreover,
> inside the OnPaint method, e.Graphics.Clear(Color.BackColor); is also not
> required
> you can instead write
>
> base.OnPaint(pevent); in your OnPaint method and it will work fine.
>
>
> I have tried the following code and it works fine for me
>
>
> public class rb : RadioButton
> {
>
> protected override void OnPaint(PaintEventArgs pevent)
> {
> base.OnPaint(pevent);
>
> }
> }
>
>
> private void Form1_Load(object sender, EventArgs e)
> {
> rb r1 = new rb();
> r1.BackColor = Color.Transparent;
> this.Controls.Add(r1);
>
> }
>
>
>
>
> "joshuaphillips@comcast.net" wrote:
>
> > Hi All,
> >
> > I have created a control that inherits from RadioButton and I have
> > overridden it's OnPaint method. It looks great, draws the background
> > with every color except with Color.Transparent. When I make the
> > controls Background color transparent, it draws it black! Is there
> > anyway to fix this?
> >
> > Inside the OnPaint method, my first line is:
> > e.Graphics.Clear(Color.BackColor);
> >
> > I have also set the control style SupportsTransparentBackColor to true.
> >
> > Any help would be greatly appreciated.
> >
> > Thanks!
> >
> >


Re: Custom Radio Button with Transparent Background by joshuaphillips

joshuaphillips
Tue Aug 16 13:59:17 CDT 2005

I actually figured it out. In my OnPaint method, I deleted the
Graphics.Clear(Color.BackColor) and just called
base.OnPaintBackground(e). That seemed to do the trick!