Implementing a button to do what file menu item does
I have a menu item File -> Export. When I select that menu item, an export dialog box comes up.
I want to implement a button in different views (eg. Home, Summary, etc.) that essentially has the same behavior as File -> Export. The file menu item is accessible under any view.
I notice the functions have the following: function_Click(object sender, EventArgs e)
I would prefer to not to rehash code. I thought about creating a new instance, then passing the arguments, but sender and e would not be the same through the button as it would be through the file menu.
Is there a way for the current view to access the file menu item (File -> Export) via a button? Just having a function to implicitly access the file menu item alone would be ideal...parameter passing would get messy for something as simple as the end result.
Typically, the sender and event arguments for a button or menu click aren't something you're going to use. As such, you can often just have a method that ALL of the event handlers reference, ie: ExportFile(), and call it from each of them.
This way, there isn't duplicated (real) code, since the event handlers each just call a method that is shared.