vb.net - ContextMenu in Visual Studio -
so i've been looking around , searching google, can't find answer. i'm trying set textbox's context menu context menu, not context menu strip. in properties window, doesn't allow me set context menu, context menu strip. can show me how set context menu textbox? know answer might somewhere already, can't find it.
you have first create contextmenu. this
private void initializealtcontextmenu() { mnucontextdefault = new contextmenu(); mnucontextdefault = this.textbox1.contextmenu; mnuitmaltmenutest = new menuitem(); mnuitmaltmenutest.index = -1; mnuitmaltmenutest.text = "test menu item"; mnuitmaltmenutest.click += new system.eventhandler(this.mnuitmaltmenutest_click); mnucontextalt = new contextmenu(); mnucontextalt.menuitems.add(mnuitmaltmenutest); } private void textbox1_mousedown(object sender, mouseeventargs e) { if (e.button == mousebuttons.right) { if ((control.modifierkeys == keys.control)) { this.textbox1.contextmenu = mnucontextalt; textbox1.contextmenu.show(textbox1, new point(e.x, e.y)); } else { this.textbox1.contextmenu = mnucontextdefault; } } }
vb.net code update
private sub initializealtcontextmenu() mnucontextdefault = new contextmenu() mnucontextdefault = me.textbox1.contextmenu mnuitmaltmenutest = new menuitem() mnuitmaltmenutest.index = -1 mnuitmaltmenutest.text = "test menu item" mnuitmaltmenutest.click += new system.eventhandler(me.mnuitmaltmenutest_click) mnucontextalt = new contextmenu() mnucontextalt.menuitems.add(mnuitmaltmenutest) end sub private sub textbox1_mousedown(sender object, e mouseeventargs) if e.button = mousebuttons.right if (control.modifierkeys = keys.control) me.textbox1.contextmenu = mnucontextalt textbox1.contextmenu.show(textbox1, new point(e.x, e.y)) else me.textbox1.contextmenu = mnucontextdefault end if end if end sub
Comments
Post a Comment