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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bullshark

    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.Select All(); and TextBox2.Select All();
    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

  • Val Savvateev

    #2
    Re: TextBox.SelectA ll() doesn't work w/ Enter Event

    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" <bullshark@scub adiving.com> wrote in message
    news:mnm5jvs6uv fhmk8nodh7170o5 mfk2pncbv@4ax.c om...[color=blue]
    > 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.Select All(); and TextBox2.Select All();
    > 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
    >[/color]


    Comment

    • Val Savvateev

      #3
      Re: TextBox.SelectA ll() doesn't work w/ Enter Event

      > PS - some website "developersdex. com" is harvesting names[color=blue]
      > from the NG and spamming membership/views for their page.
      > Are you a part of that? Please don't do it anymore.[/color]

      Are you talking to yourself?


      Comment

      Working...