c# - Programatically added checkbox to ContextMenu: Text gets chopped. Strange -
i'm trying add set of submenus contextmenu programatically. in context ran problem. example 1 takes following minimal example:
namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); } private void contextmenustrip1_opening(object sender, canceleventargs e) { foreach (propagationflags entry in propagationflags.getvalues(typeof(propagationflags))) { radiobutton rb = new radiobutton(); rb.text = entry.tostring(); rb.tag = entry; rb.autosize = true; toolstripcontrolhost ch = new toolstripcontrolhost(rb); ch.autosize = true; ((toolstripmenuitem)contextmenustrip.items["testentry"]).dropdown.items.add(ch); } } } }
the contextmenu here gets 3 subitems (which correct) unfortunately text of last item gets chopped (should inheritonly). (see screenshot 1).
when modify code , add additional item this:
namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); } private void contextmenustrip1_opening(object sender, canceleventargs e) { foreach (propagationflags entry in propagationflags.getvalues(typeof(propagationflags))) { radiobutton rb = new radiobutton(); rb.text = entry.tostring(); rb.tag = entry; rb.autosize = true; toolstripcontrolhost ch = new toolstripcontrolhost(rb); ch.autosize = true; ((toolstripmenuitem)contextmenustrip.items["testentry"]).dropdown.items.add(ch); } radiobutton rb2 = new radiobutton(); rb2.text = "test"; rb2.autosize = true; toolstripcontrolhost ch2 = new toolstripcontrolhost(rb2); ch2.autosize = true; ((toolstripmenuitem)contextmenustrip.items["testentry"]).dropdown.items.add(ch2); } } }
the code works fine , subitem numnber 3 gets complete text. see following screenshot
this happens various enums, not one.
is here aware of behavior or able reproduce it? i'm using vs 2013 professional.
i found solution or @ least workaround. helps add item programatically , remove again directly. have no clue why works , still consider being bug of c# @ least found workaround......
Comments
Post a Comment