Question : Menu And Toolbar Items in Visual Basic .net

I am new to VB.net and need help with a newbie problem. I am trying to create an application using just the controls provided with Visual Studio 2010. I have created a Menu and Toolbar with several items on it. some of the items are the same such as Copy, Cut, Paste on the Edit menu and on the toolbar.

My question is this. Is it possible to use the same click event for both the menu and toolbar item? if so how. Currently I have one event for each which duplicates the code. Below is a short example.
1:
2:
3:
4:
5:
6:
7:
Private Sub mExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mExit.Click
    Me.Close()
End Sub

Private Sub tExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tExit.Click
    Me.Close()
End Sub

Answer : Menu And Toolbar Items in Visual Basic .net

Yes, you can, like this:

Private Sub mExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mExit.Click, tExit.Click
   Me.Close()
End Sub

You can add as many events as you want, as long as you want them to do the same thing.

Random Solutions  
 
programming4us programming4us