Effect: Right click when you select TextBox or RadioButton
* Note that the ContextMenu property value to set the TextBox and Radiobutton is ContextMenu1
Private void contextMenu1_popup (Object sender, system.eventargs e) {// clear the contents of the content menu. ContextMenu1.MenuItems.clear ();
// Add a menu item for the Checked state contextMenu1.MenuItems.Add ( "Checked", new System.EventHandler (this.Checked_OnClick));.. // Add a menu item for the Unchecked state contextMenu1.MenuItems.Add ( " Unchecked ", new system.eventhandler (this.unchecked_onclick);
// Test which control it is. // If it is the CheckBox, add a menu item for the Indeterminate state. If (contextMenu1.SourceControl == checkBox1) {this.contextMenu1.MenuItems.Add ( "Indeterminate", new System. EventHandler (this.indeeeeeeterminate_onclick);
} Protected void Checked_OnClick (System.Object sender, System.EventArgs e) {if (contextMenu1.SourceControl == radioButton1) radioButton1.Checked = true; else if (contextMenu1.SourceControl == checkBox1) checkBox1.Checked = true;} protected void Unchecked_OnClick (System.Object sender, System.EventArgs e) {if (contextMenu1.SourceControl == radioButton1) radioButton1.Checked = false; else if (contextMenu1.SourceControl == checkBox1) checkBox1.Checked = false;}
protected void Indeterminate_OnClick (System.Object sender, System.EventArgs e) {if (contextMenu1.SourceControl == checkBox1) checkBox1.CheckState = System.Windows.Forms.CheckState.Indeterminate;}