c# - Right click menu and menu line -
goal:
right clicking in listview , choose different option.
problem:
there 2 problem:
*when i'm right clicking, left corner of menu not located in arrow's spot location.
*how create line in menu?
the main problem menu
need support create these 2 redmark.
private void lstv_stock_mouseup(object sender, mouseeventargs e) { switch (e.button) { // right mouse click case mousebuttons.right: contextmenu mycontextmenu = new contextmenu(); menuitem menuitem1 = new menuitem("new product"); menuitem menuitem2 = new menuitem("delete"); menuitem menuitem3 = new menuitem("add quantity"); // clear added menuitems. mycontextmenu.menuitems.clear(); mycontextmenu.menuitems.add(menuitem1); mycontextmenu.menuitems.add(menuitem2); mycontextmenu.menuitems.add(menuitem3); if (lstv_stock.selecteditems.count > 0) { foreach (listviewitem item in lstv_stock.selecteditems) { mycontextmenu.menuitems[1].visible = true; mycontextmenu.menuitems[2].visible = true; mycontextmenu.menuitems[0].visible = false; } } else { mycontextmenu.menuitems[1].visible = false; mycontextmenu.menuitems[2].visible = false; mycontextmenu.menuitems[0].visible = true; } mycontextmenu.show(lstv_stock, this.pointtoclient(cursor.position), leftrightalignment.right); menuitem1.click += new system.eventhandler(this.menuitem1_click); break; }
for positioning, can replace your
mycontextmenu.show(lstv_stock, this.pointtoclient(cursor.position), leftrightalignment.right); to
mycontextmenu.show(lstv_stock, e.location(), leftrightalignment.right); or point e.x,e.y. not this.pointtoclient, mouseeventargs generating event. can check wahat mouseevent have here.


Comments
Post a Comment