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

  • Thread starter Thread starter bullshark
  • Start date Start date
B

bullshark

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