c# - ToolStripMenuItem: Add arrow without submenu -
how can add menu item has arrow right if there submenu not show submenu?
background: managed c# application want add submenu created in unmanaged dll (using trackpopupmenu()).
in experiments, can show arrow when there items attached using "dropdownitems.add".
i tried use
toolstripmenuitem menu = new toolstripmenuitem(); m_menu.text = "item should have arrow w/o submenu"; m_menu.click += this.onmenudosomething; m_menu.dropdownitems.add(""); this still adds submenu. tried these combinations:
m_menu.dropdownitems[0].enabled = false; m_menu.dropdownitems[0].available = false; m_menu.dropdownitems[0].visible = false; but either submenu including arrow disappears or nothing @ all.
when drop down menu's handle created, assign nativewindow capture window messages , hide paint events. in fact, can hide events.
when want show drop down menu, release nativewindow's handle.
e.g.
private class nw : nativewindow { public nw(intptr handle) { assignhandle(handle); } const int wm_paint = 0xf; protected override void wndproc(ref message m) { // can ignore messages if (m.msg == wm_paint) { return; } base.wndproc(ref m); } } [stathread] static void main() { menustrip menu = new menustrip(); nw nw = null; // declared outside prevent garbage collection toolstripmenuitem item1 = new toolstripmenuitem("item1"); toolstripmenuitem subitem1 = new toolstripmenuitem("sub item1"); subitem1.dropdown.dropshadowenabled = false; subitem1.dropdown.handlecreated += delegate { nw = new nw(subitem1.dropdown.handle); }; toolstripmenuitem mimakevisible = new toolstripmenuitem("make visible"); mimakevisible.click += delegate { if (nw != null) { nw.releasehandle(); nw = null; } }; toolstripmenuitem subitem2 = new toolstripmenuitem("sub item2"); item1.dropdownitems.add(subitem1); item1.dropdownitems.add(mimakevisible); subitem1.dropdownitems.add(subitem2); menu.items.add(item1); form f = new form(); f.controls.add(menu); f.mainmenustrip = menu; application.run(f); }
Comments
Post a Comment