|
-
Mar 30th, 2004, 03:16 PM
#1
Thread Starter
Hyperactive Member
Problem with t.SelectAll()
I am trying to write a sub that would select (highlight) the default values of my text boxes as they are entered.
Here is the code. For some reason the default value is not being highlighted when I mouse into a textbox. It does, however do so when I tab into it but I think it does that by default. What is wrong with my code or technique?
VB Code:
Private Sub txtOvtAc1_Enter(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles txtOvtAc1.Enter, _
txtOvtAc2.Enter, txtOvtAc3.Enter, txtOvtAc4.Enter, _
txtOvtAf2.Enter, txtOvtBrh.Enter, txtOvtCar.Enter, _
txtOvtCpt.Enter, txtOvtFin.Enter, txtOvtLab.Enter, _
txtOvtLat.Enter, txtOvtPla.Enter, txtOvtSflr.Enter, _
txtOvtSpy.Enter, txtOvtTil.Enter, txtRegAc1.Enter, _
txtRegAc2.Enter, txtRegAc3.Enter, txtRegAc4.Enter, _
txtRegAf2.Enter, txtRegBrh.Enter, txtRegCar.Enter, _
txtRegCpt.Enter, txtRegFin.Enter, txtRegLab.Enter, _
txtRegLat.Enter, txtRegPla.Enter, txtRegSflr.Enter, _
txtRegSpy.Enter, txtRegTil.Enter
Dim t As TextBox
t = sender
t.SelectAll()
t.BackColor = Lavender
End Sub
By the way the backcor is being changed as expected.
-
Mar 30th, 2004, 03:53 PM
#2
eek , the handler looks a little long , maybe you should look into the AddHandler function , anyway , you need to set the HideSelection property to false on your textbox when selecting all.
try this ...
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ctl As Control
For Each ctl In Controls
If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
AddHandler ctl.Enter, AddressOf TextBox_Enter
End If
Next
End Sub
'/// handle all the textbox enter calls in this simple sub...
Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
Dim tb As TextBox = DirectCast(sender, TextBox)
tb.HideSelection = False
tb.SelectAll()
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Mar 30th, 2004, 04:04 PM
#3
Lively Member
try ctype :
VB Code:
Dim t As TextBox
t = cype(sender, textbox)
t.BackColor = Lavender
t.SelectAll()
-
Mar 30th, 2004, 04:09 PM
#4
Thread Starter
Hyperactive Member
Thank you both. The HideSelection = False seemed to work just fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|