Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
341
UltraMaskedEditor Inserting Spaces
posted

I decided to replace my UltraTextEditors with UltraMaskedEditors to make things a little nicer for my users.  But the (default) behavior of the UltraMaskedEditor is quite different from what I've come to expect as standard textbox behavior.

1) The first field on the form (the one that gets focus on load) now shows up with a huge number of spaces auto-selected.  (The UltraMaskedEditor.Value = dbnull)  Of course I can start to type and it will delete the spaces, so it works, but it looks really wierd.  (looks are a big deal for users)  I want it to simply show up with the cursor on the left and no spaces added or selected.

2) If I click into any UltraMaskedEditor field it puts the cursor into the field at that possition--adding spaces to the left.  Again, the UltraMaskedEditor.value is empty before I clicked in.  When I click into an empty field I'd like the cursor to automatically go to the left most possition without inserting spaces.

Is there a way to fix these two characteristics so that the UltraMaksedEditor behaves like the TextEditor?

Parents
No Data
Reply
  • 37774
    Verified Answer
    posted

    1) These aren't really spaces, per-se, but rather are the placeholders for the characters that are specified in the mask that you assigned to the controls; if you didn't specifically assign a mask, then a mask is automatically generated based on the datatype the control is expecting (controlled through the EditAs property).  This is generally expected behavior since a masked editor is generally used for when a user will be entering data following a certain pattern or restriction on input, unlike a TextBox, which allows free-form editing.

    With that being said, you could simply change the selection start location and length when the control gets focus:

    private void ultraMaskedEdit1_Enter(object sender, EventArgs e)
    {
        this.ultraMaskedEdit1.SelectionStart = 0;
        this.ultraMaskedEdit1.SelectionLength = 0;
    }

    2) This is also expected behavior allowing the user to begin editing at a specific location in the mask.  This behavior is a little harder to work around, since the user could click on a part of the editor and continue to hold the mouse down while selecting a block of text.  One approach that seems to work for me in a quick test is to derive my own control from UltraMaskedEdit and keep track of whether the control had focus before clicking, and if not, set the cursor position:

    protected override void OnMouseDown(MouseEventArgs e)
    {
        bool hasFocus = this.Focused;

        base.OnMouseDown(e);

        if (!hasFocus)
        {
            this.SelectionStart = 0;
            this.SelectionLength = 0;
        }
    }

    -Matt

Children
No Data