Chaning the Apperance of a Radio Button

J

joshuaphillips

Hi All,

I am creating a Kiosk frontend that has tons and tons of radio buttons.
(402 to be exact.) Anyhow, because this is a touch screen
application, I have added an image to each radio button that looks like
a giant oversized check mark for people with large fingers and shaky
hands. I have already added the logic that changes the image once its
radio button has been selected.

However, I need to remove the pre-existing radio button image, you
know, the little circle with the dot. Can this be done? Does anyone
have any ideas? Thanks in advance.

- Josh
 
N

Nicholas Paldino [.NET/C# MVP]

Josh,

You could override the WndProc method and handle the WM_PAINT message.
This way, you can control the painting of the control completely on your
own.

Hope this helps.
 
G

Guest

I’d suggest creating your own RadioButton class that inherits from
RadioButton and that overrides its OnPaint function, causing your code to
draw it as you see fit rather than let it draw itself in the standard manor.

Brendan
 
J

joshuaphillips

Thank you for the quick responses. To be quite honest though, I'm a
fairly inexperienced programmer and wouldn't even know where to start
with this.
 
G

Guest

The following class is a simple replacement for your use of the RadioButton
class from the sounds of it. As you see, it inherits the RadioButton class,
adds two extra properties (CheckedImage and UncheckedImage), as well as
overriding the OnPaint eventhandler.

To use it, simply set the before mentioned properties to those images you
want to be used and leave the rest to it, when the RadioButton is checked, it
will display the CheckedImage, when not, the UncheckedImage is drawn.

One little note about this code, the painting does scale the image to the
shape and size of the available area, if you do not want that, simply change
the call to DrawImage() to DrawImageUnscaled() with the same arguments.

I hope this does what you are looking for,
Brendan

public class PictureRadioButton : RadioButton
{
Image checkedImage;
Image uncheckedImage;

public Image CheckedImage
{
get
{
return checkedImage;
}
set
{
checkedImage = value;
}
}

public Image UncheckedImage
{
get
{
return uncheckedImage;
}
set
{
uncheckedImage = value;
}
}

public PictureRadioButton()
{
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
}
protected override void OnPaint(PaintEventArgs e)
{
Image paintingImage;

if(this.Checked)
{
paintingImage = this.checkedImage;
}
else
{
paintingImage = this.uncheckedImage;
}

e.Graphics.DrawImage(paintingImage, 0, 0, this.Width, this.Height);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top