467,923 Members | 1,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

select all text when textbox1 is clicked

cj
When I select textbox1 I want all text in it to be selected. I used the
textbox1_enter event to run textbox1.selectall()

This works if I tab to the box but not if it is selected by clicking on
it. I hat to have to put textbox1.selectall() in the click event too.
GotFocus event doesn't work any better than the enter event. I could
swear that back in VB4 I used the gotfocus event to select all text no
matter how the box was entered. Has this changed with .net?
Mar 28 '06 #1
  • viewed: 2270
Share:
3 Replies
Could Hide Selection property be True?

If so, set to false and see if that helps.

-Shane

"cj" <cj@nospam.nospam> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
When I select textbox1 I want all text in it to be selected. I used the
textbox1_enter event to run textbox1.selectall()

This works if I tab to the box but not if it is selected by clicking on
it. I hat to have to put textbox1.selectall() in the click event too.
GotFocus event doesn't work any better than the enter event. I could
swear that back in VB4 I used the gotfocus event to select all text no
matter how the box was entered. Has this changed with .net?

Mar 28 '06 #2
Hi cj,

Thanks for your post!

Yes, I can reproduce out this behavior. I suspect that certain winform code
after the Enter event has cancelled the selection.

Regarding this issue, we can call textbox1.selectall() in TextBox.MouseDown
event.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 29 '06 #3
cj wrote:
When I select textbox1 I want all text in it to be selected. I used the
textbox1_enter event to run textbox1.selectall()

This works if I tab to the box but not if it is selected by clicking on
it. I hat to have to put textbox1.selectall() in the click event too.
GotFocus event doesn't work any better than the enter event. I could
swear that back in VB4 I used the gotfocus event to select all text no
matter how the box was entered. Has this changed with .net?


Hello cj,

I found the same problem, here's what I have been doing -

Don't use .SelectAll() in GotFocus, Enter etc. - .NET forms do this
automatically when you Tab to the Control. (Which is what you're seeing
already)

Now put .SelectAll() in your MouseUp event and everything will work.

One advantage I found from using the MouseUp event is that modifications
can take place during the GotFocus event (such as removing formatting
from text) and the text will still be highlighted at the end.

Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Mar 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Dino M. Buljubasic | last post: by
8 posts views Thread by cj | last post: by
4 posts views Thread by Dabbler | last post: by
2 posts views Thread by dbfrey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.