469,592 Members | 1,698 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

TextBox.SelectAll() doesn't work w/ Enter Event

VSN03:C#

Create a C# Windows Form project.
Add two TextBox controls.
From the Properties of each, add an Enter Event handler.
In the generated Enter Event Handlers (textBox1_Enter & textBox2_Enter ),
add the code TextBox1.SelectAll(); and TextBox2.SelectAll();
Run the App.

When you run the app with a breakpoint at textBox1_Enter(), and
MOUSE to a field, the handler hits, executes SelectAll()
and nothing happens.

Bottom line: The event "hits" and SelectAll() does nothing.

If you TAB from field to field it works fine. The SelectAll
only fails when you MOUSE to a field. I believe that what is
happening is that the text is being selected and then
immediately repainted. My machine is too fast to see it.

Trying GotFocus is no help. Using the mouse events is out of
the question. It will interfere with normal selection.

In searching I've seen a number of complaints revolving around
this issue (none of which were implemented this way) and so
far I have turned up no solutions.

This should be easy to do, but how?

regards

bullshark

Nov 15 '05 #1
2 15112
The fact is that Enter and GotFocus events are fired _before_ any mouse
action is processed. Try this: TAB into a text box (and the text gets
selected) and _then_ click into the text (and the text gets _deselected_).
That's exactly what happens when you mouse-click into the box - 1) Enter
gets fired; 2) text gets selected by .SelectAll; 3) Mouse click (mousedown?)
gets processed by the textbox and the text gets deselected.

"bullshark" <bu*******@scubadiving.com> wrote in message
news:mn********************************@4ax.com...
VSN03:C#

Create a C# Windows Form project.
Add two TextBox controls.
From the Properties of each, add an Enter Event handler.
In the generated Enter Event Handlers (textBox1_Enter & textBox2_Enter ),
add the code TextBox1.SelectAll(); and TextBox2.SelectAll();
Run the App.

When you run the app with a breakpoint at textBox1_Enter(), and
MOUSE to a field, the handler hits, executes SelectAll()
and nothing happens.

Bottom line: The event "hits" and SelectAll() does nothing.

If you TAB from field to field it works fine. The SelectAll
only fails when you MOUSE to a field. I believe that what is
happening is that the text is being selected and then
immediately repainted. My machine is too fast to see it.

Trying GotFocus is no help. Using the mouse events is out of
the question. It will interfere with normal selection.

In searching I've seen a number of complaints revolving around
this issue (none of which were implemented this way) and so
far I have turned up no solutions.

This should be easy to do, but how?

regards

bullshark

Nov 15 '05 #2
> PS - some website "developersdex.com" is harvesting names
from the NG and spamming membership/views for their page.
Are you a part of that? Please don't do it anymore.


Are you talking to yourself?
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by theinvisibleGhost | last post: by
reply views Thread by Juna | last post: by
reply views Thread by Rainer Queck | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.