hmmm..I see your point. If you click the first time, it will select the
whole text. the second time you click, it just sets the cursor to that
position. after that, everytime you tab into that textbox using the tab key,
it just shows the cursor and does not select the entire text. so - lets try
this again and this time with 2 booleans :)
Private bHasFocus As Boolean 'class level boolean variable
Private bJustGotFocus As Boolean 'class level boolean variable
Private Sub TextBox1_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.Select(0, TextBox1.TextLength)
bHasFocus = True
End Sub
Private Sub TextBox1_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.LostFocus
bHasFocus = False
bJustGotFocus = False
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
If Not bHasFocus Or Not bJustGotFocus Then
TextBox1.Select(0, TextBox1.TextLength)
bHasFocus = True
bJustGotFocus = True
End If
End Sub
this works on my machine - or atleast i think so :) give it a try and let me
know if it helps..
imran.
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
I think this is what you had in mind but it does not work. It handles
the case of clicking into the textbox but does not handle tabbing into
the textbox. I've tried several variations of this before and after
my original post but none worked quite right.
This is such a common UI element that I thought I'd find the answer
right away after searching this group but I don't think it is there.
It seems simple enough. Anyone else want to have a run at it?
Gene H.
==============================
Option Strict On
Option Explicit On
Public Class BaseTextBox
Inherits System.Windows.Forms.TextBox
Private bJustGotFocus as boolean '(class level boolean variable)
private sub TextBox1_GotFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.GotFocus
bJustGotFocus = True
end sub
private sub TextBox1_LostFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.LostFocus
bJustGotFocus = False
end sub
private sub TextBox1_MouseDown(byval sender as object, byval e as
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
if bJustGotFocus then
me.Select(0, me.TextLength)
bJustGotFocus = false
end if
end sub
End Class
==================================
"Imran Koradia" <no****@microsoft.com> wrote in message
news:<eZ**************@tk2msftngp13.phx.gbl>...
you could do something like this:
Private bJustGotFocus as boolean '(class level boolean variable)
private sub TextBox1_GotFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.GotFocus
bJustGotFocus = True
end sub
private sub TextBox1_LostFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.LostFocus
bJustGotFocus = False
end sub
private sub TextBox1_MouseDown(byval sender as object, _
byval e as System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
if bJustGotFocus then
TextBox1.Select(0, TextBox1.TextLength)
bJustGotFocus = false
end if
end sub
should work like the address bar textbox..
hope this helps..
imran.
"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om... How do I make a TextBox behave like the address bar in IE? That is...
If focus is not on the tb, select all text if clicking on the tb or
tabbing into the tb. Clicking again deselects the text and sets the
insertion point to where clicked.
I've tried several options inheriting from TextBox but none work quite
right.
Thanks Much,
Gene H.