J
joshuaphillips
Hi All,
I have created a radio button that uses images instead of the silly
"circle" for a touch-screen kiosk application where users will have to
use their large fingers to select radio buttons. For some reason,
however, I can not get the damn thing to stop flickering! Would
anybody (with past experience in this) be able to look at my code and
see what they think? It would be greatly appreciated!
This is what I've got..
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace System.Windows.Forms
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class KioskRadioButton : RadioButton
{
public Image ImageSelected
{
get
{
return myImageSelected;
}
set
{
myImageSelected = value;
}
}
private Image myImageSelected;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public KioskRadioButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.Paint += new PaintEventHandler(MyRadioButton_Paint);
}
#endregion
private void MyRadioButton_Paint(object sender, PaintEventArgs e)
{
if (this.Checked)
{
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
e.Graphics.DrawImage(this.ImageSelected, 0,
e.ClipRectangle.Height/2 - this.ImageSelected.Height/2);
}
else
{
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
e.Graphics.DrawImage(this.Image, 0, e.ClipRectangle.Height/2 -
this.Image.Height/2);
}
}
}
}
Thank you!!
I have created a radio button that uses images instead of the silly
"circle" for a touch-screen kiosk application where users will have to
use their large fingers to select radio buttons. For some reason,
however, I can not get the damn thing to stop flickering! Would
anybody (with past experience in this) be able to look at my code and
see what they think? It would be greatly appreciated!
This is what I've got..
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace System.Windows.Forms
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class KioskRadioButton : RadioButton
{
public Image ImageSelected
{
get
{
return myImageSelected;
}
set
{
myImageSelected = value;
}
}
private Image myImageSelected;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public KioskRadioButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.Paint += new PaintEventHandler(MyRadioButton_Paint);
}
#endregion
private void MyRadioButton_Paint(object sender, PaintEventArgs e)
{
if (this.Checked)
{
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
e.Graphics.DrawImage(this.ImageSelected, 0,
e.ClipRectangle.Height/2 - this.ImageSelected.Height/2);
}
else
{
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
e.Graphics.DrawImage(this.Image, 0, e.ClipRectangle.Height/2 -
this.Image.Height/2);
}
}
}
}
Thank you!!