Note:
(1) Name:
RichTextBox-> rtxt1
Contextmenutrip-> cms1
(2 ):
(3) complete code:
<Span style = "font-size: 14px;"> using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. data. sqlclient; namespace newemployee {public partial class frm_contextmenutrip: FORM {public frm_contextmenutrip () {initializecomponent ();} // load event private void frm_contentmentr Ip_load (Object sender, eventargs e) {// load the contextmenutrip subitem toolstripitem tsitem; tsitem = addcontextmenu ("copy", cms1.items, new eventhandler (fuzhi_click )); tsitem = addcontextmenu ("-", cms1.items, null); tsitem = addcontextmenu ("Paste", cms1.items, new eventhandler (naintie_click); tsitem = addcontextmenu ("-", modified, null); tsitem = addcontextmenu ("cut", cms1.items, new eventhandler (jiantie_clic K); // right-click the shortcut menu contextmenutrip <strong> <span style = "color: # ff0000;"> rtxt1.contextmenustrip = cms1; </span> </strong >}/// <summary> /// Add sub-menu /// </Summary> /// <Param name = "text"> displayed text, if it is-, it is displayed as a split line </param> /// <Param name = "CMS"> sub-menu set to be added </param> /// <Param name = "Callback"> the submenu generated by the event triggered when you click </param> /// <returns>, if it is a separator, null is returned. </returns> toolstripmenuitem <strong> <span style = "color: # ff0000;"> addco Ntextmenu </span> </strong> (string text, toolstripitemcollection CMS, eventhandler callback) {If (text = "-") {toolstripseparator TSP = new toolstripseparator (); CMS. add (TSP); return NULL;} else if (! String. isnullorempty (text) {toolstripmenuitem tsmi = new toolstripmenuitem (text); If (callback! = NULL) {tsmi. click + = callback;} CMS. add (tsmi); Return tsmi;} return NULL;} // copy public void fuzhi_click (Object sender, eventargs e) {rtxt1.copy ();} // paste public void naintie_click (Object sender, eventargs e) {rtxt1.paste () ;}// cut public void jiantie_click (Object sender, eventargs e) {rtxt1.cut ();}}} </span>
Right-click RichTextBox to display contextmenutrip