Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Custom Radio Button with Transparent Background

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joshuaphillips@comcast.net - 16 Aug 2005 03:14 GMT
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!
swashi - 16 Aug 2005 11:51 GMT
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);
                       
        }

> Hi All,
>
[quoted text clipped - 12 lines]
>
> Thanks!
joshuaphillips@comcast.net - 16 Aug 2005 19:37 GMT
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

> Hi,
> To change the controls background color to transparent you need not set
[quoted text clipped - 41 lines]
> >
> > Thanks!
joshuaphillips@comcast.net - 16 Aug 2005 19:59 GMT
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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.