When writing winfrom, you may need to right-click and select only one item. Others are none.
Go directlyCode:
Solution --
1 /// <Summary> 2 /// Set Right-click menu 3 /// </Summary> 4 /// <Param name = "CMS"> Parameter-right-click option class </Param> 5 Public Void Ischeckedcontrol (toolstripmenuitem CMS) 6 { 7 // Set the parent container here-it can be automatically determined. Here I use handwriting. Improve Efficiency 8 Foreach (Toolstripmenuitem item In This . Tsmopacitytime. dropdownitems) 9 { 10 // The current item is not deselected 11 If (Item. Name = CMS. Name) 12 { 13 Item. Checked = True ; // Set the selected status to true 14 } 15 Else 16 { 17 Item. Checked = False ; // Set the selected status to false 18 } 19 } 20 }
Call --
1 /// <Summary> 2 /// Clock transparency settings 3 /// </Summary> 4 /// <Param name = "sender"> </param> 5 /// <Param name = "E"> </param> 6 Private Void Tsm10time_click ( Object Sender, eventargs E) 7 { 8 // Call the right-click Control Method for judging and Processing 9 Ischeckedcontrol ( This . Tsm10time );
10 This . Opacity = 0.1 ;// Set the transparency of the main form 11 }
Annotation: toolstripmenuitem classIndicatesMenustripOrContextmenustripOptional