By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

select all text when textbox1 is clicked

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.