Jos Posted January 13, 2004 Posted January 13, 2004 I'm making a program in vb.net! But with every button you have there's a event handler (ex. handles button.click) Isn't there a way that i can collect all buttons so I can call this collection 'AllButtons' and that I only have to type this 'handles' one time.(ex handles AllButtons.click) Thnx & grtz from Jos Quote
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 You could add the handlers in code as an alternative Private Sub Buttons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) MessageBox.Show("dsfsdf") End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim c As Control For Each c In Me.Controls If TypeOf c Is Button Then AddHandler c.Click, AddressOf Buttons_Click End If Next End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jos Posted January 13, 2004 Author Posted January 13, 2004 Thx :D that's exactly what I meant GRTZZZZZZZZ:cool: Quote
Jos Posted January 13, 2004 Author Posted January 13, 2004 Sorry Me again .... I don't know if there's any advantage by using the abov code , because every button has a different function so i don't know if this is 'programmatically' a good way do to this. I was testing if it was possible, but afterwards I thought 'Is this actually programmatically a right thing to do' Grtzz Josso Quote
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 If every button needs to do something different then you are probably better going with one click event per button. If multiple controls require the same (or simialr) event processing then code like the above snippet can be quite useful. Really boils down to if it works here - use it here, if not - don't. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.