context: // http://rsdn.ru/forum/message/1415538.1.aspx
  #region Using Directives
  
  using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Drawing;
  using System.Windows.Forms;
  
  #endregion
  
  namespace Iae.Windows.Forms
  {
  	public enum CheckableType
  	{
  		CheckBox,
  		RadioButton
  	}
  
  	/// <summary>
  	/// Summary description for CheckableGroupBox.
  	/// </summary>
  	[ToolboxItem(true)]
  	[ToolboxBitmap(typeof(CheckableGroupBox), "CheckableGroupBox.ico")]
  	public sealed class CheckableGroupBox : GroupBox
  	{
  		#region Constants
  
  		private const int WSCOUNT = 5;
  
  		#endregion
  
  		private IContainer components = null;
  
  		#region Constructors
  
  		public CheckableGroupBox()
  		{
  			// This call is required by the Windows Form Designer.
  			InitializeComponent();
  
  			_checkBox = new CheckBox();
  			_checkBox.Name = "checkBox";
  			_checkBox.TabIndex = 1;
  			_checkBox.Text = string.Empty;
  			_checkBox.Checked = false;
  			_checkBox.AutoCheck = true;
  			_checkBox.Location = new Point(8, 0);
  			_checkBox.Size = new Size(16, 16);
  			_checkBox.CheckedChanged += new EventHandler(_checkBox_CheckedChanged);
  			_checkBox.Click += new EventHandler(_checkBox_Click);
  
  			_radioButton = new RadioButton();
  			_radioButton.Name = "radioButton";
  			_radioButton.TabIndex = 1;
  			_radioButton.Text = string.Empty;
  			_radioButton.Checked = false;
  			_radioButton.AutoCheck = false;
  			_radioButton.Location = new Point(8, 0);
  			_radioButton.Size = new Size(16, 16);
  			_radioButton.CheckedChanged +=new EventHandler(_radioButton_CheckedChanged);
  			_radioButton.Click += new EventHandler(_radioButton_Click);
  
  			this.Controls.Add(_checkBox);
  			this.Controls.Add(_radioButton);
  
  		}
  
  		#endregion
  
  		#region Fields
  
  		private bool _isFirstTime = true;
  		private bool _lastCheckedState = false;
  		private bool _autoCheck = true;
  		private CheckableType _checkableType = CheckableType.CheckBox;
  		private Control _parent;
  		private ArrayList _radioButtons = new ArrayList();
  		private CheckBox _checkBox;
  		private RadioButton _radioButton;
  
  		#endregion
  
  		#region Properties
  
  		[Browsable(true)]
  		[Description("The text contained in the control.")]
  		public new string Text
  		{
  			get
  			{
  				if (base.Text.Length > WSCOUNT)
  				{
  					return base.Text.Substring(WSCOUNT);
  				}
  				else
  				{
  					return base.Text;
  				}
  			}
  			set
  			{
  				base.Text = new string(' ', WSCOUNT) + value;
  
  				// by CHD.Vosogop
  				int textWidth = (int) CreateGraphics().MeasureString (value, Font).Width + 20;
  				_checkBox.Text = value;
  				_radioButton.Text = value;
  				_checkBox.Size = new Size(textWidth, 18);
  				_radioButton.Size = new Size(textWidth, 18);
  			}
  		}
  
  		[Browsable(true)]
  		[DefaultValue(true)]
  		[Description("Causes the checkable group box to automaticaly change state when clicked.")]
  		public bool AutoCheck
  		{
  			get
  			{
  				return _autoCheck;
  			}
  			set
  			{
  				_autoCheck = value;
  				_checkBox.AutoCheck = value;
  			}
  		}
  
  		[Browsable(true)]
  		[DefaultValue(false)]
  		[Description("Indicates whether the radio button is checked or not.")]
  		public bool Checked
  		{
  			get
  			{
  				switch (_checkableType)
  				{
  					case CheckableType.CheckBox:
  						return _checkBox.Checked;
  					case CheckableType.RadioButton:
  						return _radioButton.Checked;
  					default:
  						return _checkBox.Checked;
  				}
  			}
  			set
  			{
  				switch (_checkableType)
  				{
  					case CheckableType.CheckBox:
  						_checkBox.Checked = value;
  						break;
  					case CheckableType.RadioButton:
  						_radioButton.Checked = value;
  						break;
  					default:
  						break;
  				}
  			}
  		}
  
  		[Browsable(true)]
  		[DefaultValue(CheckableType.CheckBox)]
  		[Description("Determines the checkable type of the control (check box or radio button).")]
  		public CheckableType CheckableType
  		{
  			get
  			{
  				return _checkableType;
  			}
  			set
  			{
  				_checkableType = value;
  				switch (_checkableType)
  				{
  					case CheckableType.CheckBox:
  						_checkBox.Visible = true;
  						_radioButton.Visible = false;
  						break;
  					case CheckableType.RadioButton:
  						_checkBox.Visible = false;
  						_radioButton.Visible = true;
  						break;
  				}
  			}
  		}
  
  		#endregion
  
  		#region Overrides
  
  		protected override void OnPaint(PaintEventArgs e)
  		{
  			if ((_lastCheckedState != _checkBox.Checked) || _isFirstTime)
  			{
  				switch (_checkableType)
  				{
  					case CheckableType.CheckBox:
  						_checkBox_CheckedChanged(this, new EventArgs());
  						break;
  					case CheckableType.RadioButton:
  						_radioButton_CheckedChanged(this, new EventArgs());
  						break;
  					default:
  						break;
  				}
  				if (_isFirstTime)
  				{
  					_isFirstTime = false;
  				}
  			}
  			base.OnPaint(e);
  		}
  
  		/// <summary>
  		/// Clean up any resources being used.
  		/// </summary>
  		protected override void Dispose( bool disposing )
  		{
  			if( disposing )
  			{
  				if (components != null) 
  				{
  					components.Dispose();
  				}
  			}
  			base.Dispose( disposing );
  		}
  
  		#endregion
  
  		#region 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()
  		{
  			// 
  			// CheckableGroupBox
  			// 
  			this.ParentChanged += new System.EventHandler(this.CheckableGroupBox_ParentChanged);
  
  		}
  		#endregion
  
  		#region Event Handlers
  
  		private void _checkBox_CheckedChanged(object sender, EventArgs e)
  		{
  			if ((_lastCheckedState != _checkBox.Checked) || _isFirstTime)
  			{
  				_lastCheckedState = _checkBox.Checked;
  				if (!this.DesignMode)
  				{
  					foreach (Control control in this.Controls)
  					{
  						if ((control != null) && (control != _checkBox))
  						{
  							control.Enabled = _lastCheckedState;
  						}
  					}
  				}
  			}
  			if (CheckedChanged != null)
  			{
  				CheckedChanged(this, new EventArgs());
  			}
  		}
  
  		private void _radioButton_Click(object sender, EventArgs e)
  		{
  			if ((_radioButton.Checked == false) && AutoCheck)
  			{
  				_radioButton.Checked = true;
  			}
  
gt: 			if (Click != null)