Depending on the button name, the method is called directly, which is applicable to the user's operation rights Management of the button.
/// <summary> ///Menu button Click event/// </summary> voidUsrmenu1_usercontrolmenuitemclick (Objectsender, EventArgs e) { #regionMyregion////btngetparam Getting Parameters //if (nbi.name = = "Btngetparam")//{ //Btngetparam_click (sender, E); //} ////btndelete Delete //if (nbi.name = = "Btndelete")//{ //Btndelete_click (sender, E); //} ////btnsaveform Save //if (nbi.name = = "Btnsaveform")//{ //Btnsaveform_click (sender, E); //} ////btnsaveform Refresh //if (nbi.name = = "Btnrefresh")//{ //Btnrefresh_click (sender, E); //} //if (nbi.name = = "Btnupdsysid")//{ //Btnupdsysid_click (sender, E); //} #endregion //ClassName is the class where the method resides Try{ToolStripMenuItem Nbi=(ToolStripMenuItem) sender;//Get button object MethodInfo mm= This. GetType (). GetMethod (Nbi.name +"_click");//The event that invokes the button//obj is the return value of the method, and the second parameter of invoke is the parameter to be executed by the method, which is the array Objectobj = mm. Invoke ( This,New Object[2] {sender, E}); } Catch(Exception ex) {MessageBox.Show (ex). Message.tostring ()); } }
C # Reflection, method invocation, auto Invoke method, invoke method based on button name, C # button permission management