[RESOLVED] Handler Question
Using VB2012 ...
Rather than have a single subroutine for each textbox control getting focus on a form, I grouped them all like this:
Code:
Private Sub txtAddress_GotFocus(sender As Object, e As EventArgs) Handles _
txtAddress.GotFocus, txtPhone.GotFocus, txtVendor.GotFocus, _
txtCity.GotFocus, txtZip.GotFocus
End Sub
From there I can do various things like change the backcolor/forecolor but considering they are all textboxes I would like to select all the text when they get focus ... but I can't figure out the syntax to do that. I would think I have to test for a textbox and then select all if true ... but how?
Thanks,
Ken
Re: [RESOLVED] Handler Question
Oh .. kpmc ... the textboxes exist across several panels so group boxes, while more elegant, isn't so simple. Thanks.
Re: [RESOLVED] Handler Question
Quote:
Originally Posted by
KenB
Oh .. kpmc ... the textboxes exist across several panels so group boxes, while more elegant, isn't so simple. Thanks.
panels have control collections also ;)
Re: [RESOLVED] Handler Question
But with multiple panels, I'd do it the way he's doing it, anyways. It's not THAT many.
By the way, there may be an infinitesimally small advantage to using DirectCast rather than CType for that cast. I have read that it is faster in cases like this, but have never tested it. If there's a difference, it's going to be too small to notice. FAR too small to notice in this case.
Re: [RESOLVED] Handler Question
While you can used code to loop through and add handlers, perhaps you don't want all the textboxes on the form.
In any case, if you hold down the ctrl key and select all the textboxes you want to include in the handles clause, then generate the event handler sub from the event list, it adds all the controls to the handles clause for you so its not like you have type all that text yourself anyway.
Re: [RESOLVED] Handler Question
Quote:
Originally Posted by
passel
While you can used code to loop through and add handlers, perhaps you don't want all the textboxes on the form.
In any case, if you hold down the ctrl key and select all the textboxes you want to include in the handles clause, then generate the event handler sub from the event list, it adds all the controls to the handles clause for you so its not like you have type all that text yourself anyway.
There is certainly a practicality vs laziness ratio to be had here...
Re: [RESOLVED] Handler Question
Quote:
Originally Posted by
Shaggy Hiker
But with multiple panels, I'd do it the way he's doing it, anyways. It's not THAT many.
By the way, there may be an infinitesimally small advantage to using DirectCast rather than CType for that cast. I have read that it is faster in cases like this, but have never tested it. If there's a difference, it's going to be too small to notice. FAR too small to notice in this case.
In my searching I came across this comparison ... https://www.codeproject.com/Articles...tCast-Vs-CType