That doesn't do anything yet, so it can't be inefficient in the usual sense. Are you looking for an alternative to typing all those button names by hand? If so, I can think of 3 ways:
1. If you already have the buttons laid out on a form, Shift-Select them all. Go to the Properties window and click on the lightning-icon to get a list of events. Double click on the Click event in the list. The result will be like the code you posted.
2. In code, you could use a loop with AddHandler to assign a sub to all the buttons. Search this forum for AddHandler for examples.
3. Make your own version of the Button class. Select Project/Add Class ... in Visual Studio, give it a name (e.g. ButtonEx) and code the OnClick sub:
After you build the project, ButtonEx will appear in the toolbox with a cogwheel icon. In the Designer, you can drag these onto your form the same way as a normal buttons, but they will all have your special Click code.Code:Public Class ButtonEx Inherits Button Protected Overrides Sub OnClick(e As System.EventArgs) 'put your button click code here MyBase.OnClick(e) End Sub End Class
BB
EDIT: I didn't see your edited post. You probably want method 2.




Reply With Quote