Tuesday, February 26, 2008

Use PerformClick to call a Menu Item's Click event from your code

Another easy one, and I've done this before too, just forgot about it.

But I had an Menu Click event that I wanted to call from code.  When you call Menuitem1.Click you get an error, because it expects a sender and some args.  I started down the path of supplying the arguments, when I stumbled across the PerformClick event, that you can just call.  Yeah.

Another option would be to move your code from the Menu Click event to another function, and call that function from both the MenuClick event and from any where else you would like to.

No comments: