This is a migrated thread and some comments may be shown as answers.

MaskedEditBox blues

4 Answers 67 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Helen
Top achievements
Rank 2
Helen asked on 28 Feb 2015, 02:17 AM
I made my first experiments with this control. I was astounded that I had to do the following to get the cursor to be at the start of the string when the user tabbed into the control (otherwise it was at the end of it ???)

    private void radMaskedEditBox1_Enter(object sender, EventArgs e)
    {
         radMaskedEditBox1.SelectionLength = 0;
         radMaskedEditBox1.SelectionStart = 0;           
    }

So okay, I didn't expect this behavior, but ...

Next, I wanted to put a blank (or underscore, or whatever) into the text when the number my user entered had less digits than the full amount.

Wow! Here's one attempt:

     private void radMaskedEditBox1_Leave(object sender, EventArgs e)
     {
         int len = radMaskedEditBox1.Text.Length;
         string val = radMaskedEditBox1.Text;
         while (val.EndsWith("_"))
             val = "0" + val.Substring(0, val.Length - 1);
         radMaskedEditBox1.Text = val;
     }

Whatever leading character I tried (" ", "0", "_") the result was the same. There is simply no way that I can see to right-justify the number, although that is how most numbers are presented.

Have I missed something? Sure the cursor should automatically go to the start of the field on entry, and numbers should be right justified?

Cheers,

Helen

4 Answers, 1 is accepted

Sort by
0
Helen
Top achievements
Rank 2
answered on 28 Feb 2015, 09:03 PM
OK, got it to right-justify by setting the "TextAlign" property to "Right".

I still can't get it to put the decimal point such that there are exactly 2 digits behind it, if the text entered is less than the full length of allowed.

I'd like to suggest that you consider allowing that in a future release. If the mask is "xxx.xx" there doesn't seem to be a way to enter "12.34" and have it converted to "12.34" rather than "123.4"

Furthermore, is there a way to exit the control when the user hits "Return"? I seem to have to hit the tab key.
0
Stefan
Telerik team
answered on 04 Mar 2015, 08:30 AM
Hi Helen,

Thank you for writing.

I am glad that you have found a suitable way to handle the cursor as per your requirement. Having it at the end is a standard behavior you can observe in the standard controls as well.

As I mentioned in your ticket inorder to have a numeric mask with two digits after the decimal point, you can set the MaskType to Numeric and the Mask to "n2". This way you can enter "1.23", "12.34" or "123.45". Note however, that your users will be able to add more than 3 numbers prior the decimal point with this mask and if you want to limit this, perhaps you should use the Validating events and some ErrorProvider. 

In regards to handling return as tab, you can capture the return key press and call the SelectNextControl method in the KeyUp event for example:
private void radMaskedEditBox1_KeyUp(object sender, KeyEventArgs e)
{
    if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
    {
        this.SelectNextControl(radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.TextBoxControl, true, true, true, true);
    }
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Helen
Top achievements
Rank 2
answered on 04 Mar 2015, 04:25 PM
I'm sorry, but I don't consider writing a bunch of event handlers as a suitable solution for this problem. The fact is, this control does not easily handle numeric input in an intuitive way. Perhaps the real solution is to not write one-size-fits-all controls, but to write some specific to common needs. I have been trying to convert all my controls to Telerik, but I already have a numeric textbox control that does exactly what I need, from a different company, and without a bunch of unintuitive event handlers.
0
Stefan
Telerik team
answered on 09 Mar 2015, 02:16 PM
Hi,

With RadMaskedEditBox we aim at supporting the most common masks used out there and I believe we do offer great flexibility which allows for further customizations. 

The event used below is a standard way in Windows Forms to move the focus from one control to another.

I hope that in your ticket we will be able to see what is it that you are missing and help you achieve it.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
MaskedEditBox
Asked by
Helen
Top achievements
Rank 2
Answers by
Helen
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or