Question How do I find which TextBox when using Private Sub TextBoxes_MouseUp ~

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
I sometime use a 'catch-all' procedure for an event for all textboxes, such as:

VB.NET:
    Private Sub TextBoxes_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseUp, TextBox2.MouseUp, TextBox3.MouseUp, TextBox4.MouseUp, TextBox5.MouseUp, TextBox6.MouseUp, TextBox7.MouseUp, TextBox8.MouseUp, TextBox9.MouseUp, TextBox10.MouseUp, TextBox11.MouseUp, TextBox12.MouseUp

        'Do something here to whichever TextBox I happen to be in...

    End Sub

Is there a way of finding out which textbox I am in?

Thank you.
 
The 'sender' parameter always refers to the instance of the class that raised the event.
VB.NET:
Dim tb As TextBox = CType(sender, TextBox)
 
Back
Top