textboxes and subroutines

tcross

Member
Joined
Oct 26, 2006
Messages
10
Programming Experience
1-3
I am working on a program which has many textboxes on one form. I know how to assign handles to subroutines which will make all the required textboxes call the same subroutine when clicked on.

My question is when one of the textboxes is clicked on - how do you pass the name of the textbox that was clicked on to the subroutine?

I am doing it now with a IF - FOCUSED line in the subroutine for each and every textbox however this creates a lot of code and I believe there has to be a better way.

Thanks
 
The 'sender' argument in every event handler is a reference to the object that raised the event. As nooch suggests, you simply cast the sender as type TextBox and there you have it. In fact, you don't even have to cast if you don't specifically need to use members of that type, but in your case you do:
VB.NET:
Dim tb As TextBox = DirectCast(sender, TextBox)
nooch, you won't find anything about DirectCast in the Object Browser because it's not a member of any type. It's a VB.NET keyword. Open your MSDN library and filter by VB, then put it into the index search box.
 
Back
Top