|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DotNetIdeas.CF.RunTime;
namespace TransparentControlSample
{
public class CcTransparentRadioButton : CcTransparentControl
{
public event EventHandler CheckedChanged;
private bool _checked = false;
public bool Checked
{
get
{
return _checked;
}
set
{
if (value)
{
foreach (Control control in this.Parent.Controls)
{
if (typeof(CcTransparentRadioButton) == control.GetType())
{
CcTransparentRadioButton radioButton = (CcTransparentRadioButton)control;
if (radioButton != this && radioButton.Checked) radioButton.Checked = false;
}
}
}
if (_checked != value)
{
_checked = value;
this.Invalidate();
}
}
}
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gfx = pe.Graphics;
SizeF size = gfx.MeasureString(this.Text, this.Font);
int buttonHeight = (int)size.Height;
gfx.DrawEllipse(ForeColorPen, 0, 0, buttonHeight, buttonHeight);
int offset = DpiHelper.Scale(3);
if (_checked) gfx.FillEllipse(new SolidBrush(this.ForeColor), offset, offset, buttonHeight - offset * 2, buttonHeight - offset * 2);
gfx.DrawString(this.Text, this.Font,
new SolidBrush(this.ForeColor), ClientRectangle.Left + buttonHeight + DpiHelper.Scale(5), ClientRectangle.Top);
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
if (!Checked)
{
Checked = true;
if (CheckedChanged != null) CheckedChanged(this, null);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.