Click here to Skip to main content
13,353,322 members (53,226 online)
Click here to Skip to main content
Add your own
alternative version


62 bookmarked
Posted 17 Jun 2002

Adding an LED to your radiobuttons

, 2 Jul 2002
Rate this:
Please Sign up or sign in to vote.
Enhance the visual impact of your radio buttons


After writing a software front end for my Kenwood R-5000 shortwave receiver, I was unhappy with the look of the white circle/black dot standard radio buttons. After all, my Kenwood has these very cool LEDs in the top corner of each button, to show which is currently active. How to simulate this in C# to enhance my project? After tinkering with Alexandr Khilov's very nice cute button, I hit on it. Subclass it as a RadioButton instead of a Button,draw a triangle in the top left corner, set it to a color, then add a little code to tie the whole thing together! I find the end results to be very attractive visually, and hopefully you'll find uses for it I've never considered. Here's a snapshot of the demo project to show you what's possible. Not necessarily tasteful you understand, but possible.

More about the control

I've added a couple of additional touches that are absent from Alex's project, the main one being an attribute header for each property, so a little help is available in design mode:

Description("Sets the width of the LED in % of control's width")
public int LEDWidth{
    get {return m_width;}
    set {m_width = value; Invalidate();

And of course, several new elements had to be added, here's a quick rundown:

  • LEDColor: The color of the LED in OFF Mode. My favorites being DarkRed, Green and DarkGoldenRod (for a yellow LED).

  • LEDWidth: an integer that represents the percentage of the control's width you want the LED to cover.

  • LEDHeight: an integer that represents the percentage of the control's height you want the LED to cover. You can make some VERY strange looking LED's by playing with these numbers. I find, about a 10% width and 40% height looks good for a rectangular control.

  • LEDOffset: The number of pixels between the edge of the control and the LED.

I also changed a couple of Alex's identifiers, since I prefer the button to gradient from top to bottom instead of left to right:

  • topColor: sets the color for the top of the control, that will eventually gradient into the color set by the property bottomColor. Transparency values are similarly named.

I added a boolean variable onOff in order to pass the button's state to the onPaint event handler, and added some extra code to Alex's already excellent work:

if(onOff == true){
    c3 = System.Windows.Forms.ControlPaint.LightLight(m_ledcolor);
    c3 = System.Windows.Forms.ControlPaint.Dark(m_ledcolor);
SolidBrush sb = new SolidBrush(c3);
Pen blackPen = new Pen(Color.Black , 2);

//set the drawing points for the triangle
Point point1 = new Point( m_offset, m_offset);
Point point2 = new Point(m_offset, triHeight());
Point point3 = new Point(triWidth(),m_offset);
Point point4 = new Point(m_offset,m_offset);

//put them all in an array of Points
Point[] triPoints = {
pe.Graphics.DrawPolygon(blackPen, triPoints);

//thanks to Anonymous for this suggestion!

Of particular interest would probably be the ControlPaint.LightLight and ControlPaint.Dark methods. No need to mess with bit masking or luminosity values to make the color changes, these functions do all the dirty work! The triHeight() and triWidth() functions, simply calculate the number of pixels needed for the correct size of the triangle.

virtual protected int triHeight(){
    float x;
    x = this.Height * ((float)m_height/100);
    return (int)x;
virtual protected int triWidth(){
    float x;
    x = this.Width * ((float)m_width/100);
    return (int)x;

Thanks to DeepStack for pointing out how to force the Button's Appearance property to Button instead of Default.

Possible enhancements would include:

  • Allowing the designer to select which corner to place the LED. I'm happy with the upper left-hand corner, so I left that as a future project.

  • Changing the shape of the LED to a circle or a square or a diamond or whatever. Again, I was going for a triangular shape to simulate a real-life radio button, so I left it as is.

About Duane Lunday

I'm a very experienced programmer who recently signed a long term non-compensation agreement with my previous employer of 10 years. I've been using my downtime to catch up on C# and the .NET framework in general. If you're interested in shortwave radio software and spy stations in particular, download my SpyCatcher software written in C# at


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Duane Lunday
Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionAppearance Pin
SLareau27-Apr-09 12:20
memberSLareau27-Apr-09 12:20 
GeneralAppearence is read-only Pin
Corey W28-Feb-07 13:12
memberCorey W28-Feb-07 13:12 
GeneralWeb Version Pin
NestorLeone3-Dec-03 6:17
memberNestorLeone3-Dec-03 6:17 
GeneralRe: Web Version Pin
vbcv17-Jun-04 20:14
membervbcv17-Jun-04 20:14 
QuestionError in source code? Pin
gooky31-Jan-03 15:09
membergooky31-Jan-03 15:09 
AnswerRe: Error in source code? Pin
vbcv17-Jun-04 20:03
membervbcv17-Jun-04 20:03 
AnswerRe: Error in source code? Pin
romias9-Feb-05 3:43
memberromias9-Feb-05 3:43 
GeneralAppearance property Pin
James T. Johnson21-Jun-02 15:27
subeditorJames T. Johnson21-Jun-02 15:27 
GeneralRe: Appearance property Pin
Duane Lunday22-Jun-02 19:29
memberDuane Lunday22-Jun-02 19:29 
GeneralRe: Appearance property Pin
DeepStack26-Jun-02 1:55
memberDeepStack26-Jun-02 1:55 
GeneralRe: Appearance property Pin
Duane Lunday3-Jul-02 6:29
memberDuane Lunday3-Jul-02 6:29 
GeneralAntialiasing :) Pin
Anonymous20-Jun-02 22:44
memberAnonymous20-Jun-02 22:44 
GeneralRe: Antialiasing :) Pin
Duane Lunday21-Jun-02 7:00
memberDuane Lunday21-Jun-02 7:00 
QuestionWhat is a 'long term non-compensation agreement' ? Pin
Christian Graus18-Jun-02 17:33
memberChristian Graus18-Jun-02 17:33 
AnswerRe: What is a 'long term non-compensation agreement' ? Pin
Duane Lunday18-Jun-02 17:43
memberDuane Lunday18-Jun-02 17:43 
GeneralRe: What is a 'long term non-compensation agreement' ? Pin
TLWallace.NET7-Jul-06 13:26
memberTLWallace.NET7-Jul-06 13:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 3 Jul 2002
Article Copyright 2002 by Duane Lunday
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid