mitra_subhasis
asked on
For text box...
Suppose I have a textbox control, say Text1. Whenever I focus on the textbox the text will automatically selected(ie. in windows it will be hilighted in blue) and whenever I write on it it deletes the previous content.
Please write some code.
regards
Subhasis
Please write some code.
regards
Subhasis
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi mitra,
Try the following code. Suppose I have a text box in the form1 name text1.
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.BackColor = vbWhite
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Text1.Text = ""
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.BackColor = vbBlue
Text1.SetFocus
End Sub
Cheers,
Sweetpillow :)
Try the following code. Suppose I have a text box in the form1 name text1.
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.BackColor = vbWhite
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Text1.Text = ""
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.BackColor = vbBlue
Text1.SetFocus
End Sub
Cheers,
Sweetpillow :)
ASKER
That's very pretty...
Thanking you,'
Subhasis
Thanking you,'
Subhasis
sweetpillow, it would indeed work, however you would need to reset the colours in the KeyDown event otherwise it will still stay white on blue.
Anyway the snippet I posted achieves everything required with less code. ryancys's suggestion would also work but sendkeys is not necessarily the most reliable method.
Anyway the snippet I posted achieves everything required with less code. ryancys's suggestion would also work but sendkeys is not necessarily the most reliable method.
Ah well mitra_subhasis, you chose a solution which is your right, I would stand by my last comment that sendkeys is not necessarily the MOST reliable way to achieve this when you can do it more simply with the suggestion I gave!
With Text1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub