RadioButton double-click

  • Thread starter Thread starter Gabriel Lozano-Morán
  • Start date Start date
G

Gabriel Lozano-Morán

Is there a clean way to handle a radiobuttons double-click? I have a form
with 3 radiobuttons and a OK and Cancel button. I want to invoke the Ok
buttons click when a radiobutton is double-clicked...

Gabriel Lozano-Morán
 
You can derive a new control from the RadioButton control and enable the
double-click behavior as shown below.

public class DoubleClickRadioButton : RadioButton
{
public DoubleClickRadioButton()
{
this.SetStyle(ControlStyles.StandardClick |
ControlStyles.StandardDoubleClick, true);
}
}

Then you can hook into the DoubleClick event of each
"DoubleClickRadioButton" control and route the event to the same handler. In
this handler you can call the PerformClick method of the OK button.

public class Form1 : System.Windows.Forms.Form
{
...

public Form1()
{
InitializeComponent();

this.radioButton1.DoubleClick += new
EventHandler(DoubleClickRadioButton_DoubleClick);
this.radioButton2.DoubleClick += new
EventHandler(DoubleClickRadioButton_DoubleClick);
this.radioButton3.DoubleClick += new
EventHandler(DoubleClickRadioButton_DoubleClick);
}

...

private void DoubleClickRadioButton_DoubleClick(object sender, EventArgs
e)
{
this.btnOK.PerformClick();
}
}
 
Back
Top