select all text when textbox1 is clicked

  • Thread starter Thread starter cj
  • Start date Start date
C

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?
 
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.
 
cj said:
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.
 
Back
Top