c# - How to check/uncheck menu item and keep windows on top -
i writing c# web application have menu strip option keep windows on top. name of alwaysontoptoolstripmenuitem
, during page load keep checked because start form being on top:
private void frmmain_load(object sender, eventargs e) { alwaysontoptoolstripmenuitem.checked = true; }
i have following code allow user select , change based on condition of menu item:
private void alwaysontoptoolstripmenuitem_click(object sender, eventargs e) { if (alwaysontoptoolstripmenuitem.checked == true) { messagebox.show("true - setting false"); alwaysontoptoolstripmenuitem.checked = false; this.topmost = false; } if (alwaysontoptoolstripmenuitem.checked == false) { messagebox.show("false - setting true"); alwaysontoptoolstripmenuitem.checked = true; this.topmost = true; } }
when it's commented out, if go through menu option, clicking doesn't uncheck , clicking again doesn't check it. remains checked.
the messagebox
displays both prompt no matter choose.
how can fix following:
- change check uncheck , uncheck check based on current state?
- also, make form topmost based on selection?
change second if
statement else if
, because change checked = true
, in second check (which equals true), it'll switch checked = false
Comments
Post a Comment