Home Forums WinForms controls Other WinForms controls Text Selection on Focus in WinTextBox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18153 |

    Hi,

    we converted our project to .NET2.0 and found out that TextBoxes behave differently than in 1.1… when tabbing to them, the contents are no longer selected.

    The XCeed WinTextBox.TextArea.SelectOnFocus seems to be the solution to this problem, but it is by default false.

    We have a large number of textboxes in our application – all of them would have to be converted by hand and every new TextBox would need this flag – if someone forgets this, the box would behave differently than the others – our customers already complained about it.

    So my question: is there any possibility to globally set SelectOnFocus for our application? Or is there any other solution for our problem?

    Thanks in advance,
    Mike

    Imported from legacy forums. Posted by mike_t (had 4334 views)

    User (Old forums)
    Member
    Post count: 23064

    The WinTextBox has the same behavior in both .NET1.1 and .NET 2.0 with our latest version (3.2.6403.0). The WinTextBox.TextBoxArea.SelectOnFocus is false by default. We just tested it.

    So it is possible that you have a version that, for some reason, had a bug which made the behavior differ from one version of .NET to the other.

    Unfortunately, in your case, you will have to set the SelectOnFocus to true everywhere.

    The only other solution is to create a custom class deriving from WinTextBox, override the CreateTextBoxArea, set the SelectOnFocus to true in there, and then do a CTRL-SHIFT-H in your project, and replace all the Xceed.Editors.WinTextBox (and/or WinTextBox) with the name of this new class.

    i.e :
    <i>
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Xceed.Editors;

    namespace WindowsApplication29
    {
    public class AutoSelectWinTextBox : WinTextBox
    {
    protected override TextBoxArea CreateTextBoxArea()
    {
    TextBoxArea textBoxArea = base.CreateTextBoxArea();
    textBoxArea.SelectOnFocus = true;

    return textBoxArea;
    }
    }
    }
    </i>

    Imported from legacy forums. Posted by André (had 275 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply, we will implement the derived solution – so we are prepared for the future if something changes in .NET 3 😉

    Thanks,
    Mike

    Imported from legacy forums. Posted by mike_t (had 379 views)

    User (Old forums)
    Member
    Post count: 23064

    A rew more WinTextBox questions:

    1. If you have TextBoxArea.SelectOnFocus set to false, why won’t a WinTextBox keep the SelectionStart and SelectionLength state when you tab away then back to it? The standard Windows TextBox does.

    2. Why does the WinTextBox always position the caret to the end of the text when it gets focus via the keyboard?

    3. If you have TextBoxArea.SelectOnFocus set to true, all the text gets selected not only when you focus the control via a keystroke, but also when you give it focus via a mouse click. Standard windows behavior is to select all text only when focusing the control via the keyboard (I mean on data-entry type forms, not the few exceptions like the address bar in IE).

    Any work-arounds for these?

    Imported from legacy forums. Posted by Glenn (had 461 views)

    User (Old forums)
    Member
    Post count: 23064

    Due to masking and how text is manipulated in the TextBoxArea, some standard .NET TextBox behavior are impacted, as those you mention here. There is nothing we can do to change this.

    Imported from legacy forums. Posted by André (had 4856 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.