winforms - Getting info on C# menu items after a click -
another question c# newbie- use single function respond list of choices offered in menu. when run in debug mode can hover mouse on sender , clear sender has information need, both index of item in menu , text associated it. however, have not figured out how write code in way looking for. following not compile:
int device; private void mymenuiteminputclick(object sender, eventargs e) { device = sender.index; }
what see when put breakpoint on mymenuiteminputclick , put mouse on sender is:
sender {windows.system.forms.menuitem, items.count:0, text:stereo mix (realtek high defini}
moving mouse on "+" sign becomes "-" , list of debug statements drops down shows there item index want. how write code item i'm looking for?
cast sender menuitem possibly solve problem.
int device; private void mymenuiteminputclick(object sender, eventargs e) { device = ((menuitem)sender).index; }
the variation bharath mentioned like,
int device; private void mymenuiteminputclick(object sender, eventargs e) { var menuitem = sender menuitem; if(menuitem != null) device = menuitem.index; }
Comments
Post a Comment