Click here to Skip to main content
15,887,214 members
Articles / Programming Languages / Visual Basic 10
Tip/Trick

Multiple Event Handling for the Lazy Ones

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
24 May 2011CPOL 11.1K   1  
Handle code redundancy for many controls in one subroutine
When you want to replace all spaces entered in Textboxes, say txtH1,txtH2,txtH3,txtH4, instead of writing separate event handlers like :
VB
 Private Sub txtH1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtH1.TextChanged
'Code
End Sub

VB
 Private Sub txtH2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtH2.TextChanged
'Code
End Sub

and so on,

VB
 Private Sub txtH1to7TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtH1.TextChanged,txtH2.TextChanged, txtH3.TextChanged,txtH4.TextChanged
'Code
End Sub


would do the job.

This can be extended to the same event of any number of the same type of control.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --