Completed
Last Updated: 08 Apr 2019 10:04 by ADMIN
Shawn
Created on: 05 Feb 2019 18:26
Category: Editors
Type: Bug Report
1
MaskedEditBox Click EventHandler not invoked and SelectionStart/Length OnClick is ignored

Steps:

1) Add a textbox to a form. Set tabindex set to 0.

2) Add a RadMaskedEditBox with tabindex set to 1, and add the code listed below.

        public Form1()
        {
            InitializeComponent();

            this.radMaskedEditBox1.MaskType = MaskType.Standard;
            this.radMaskedEditBox1.Mask = "000000";
            this.radMaskedEditBox1.PromptChar = '#';
            this.radMaskedEditBox1.SelectionStart = 0;
            this.radMaskedEditBox1.SelectionLength = 0;
            
            this.radMaskedEditBox1.Enter += radMaskedEditBox1_Enter;
            this.radMaskedEditBox1.Click += radMaskedEditBox1_Click;
            this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.Click += TextBoxItem_Click;
        }

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

        void TextBoxItem_Click(object sender, EventArgs e)
        {
            this.radMaskedEditBox1.SelectionStart = 0;
        }

        void radMaskedEditBox1_Click(object sender, EventArgs e)
        {
            
        }


3) Add breakpoints to all 3 RadMaskedEditBox events.

4) Run the app. Press tab key. (Enter event works as expected for the MaskedEditBox class).

5) Close and re-run app. Click the end of the MaskedEditBox. Click event is not invoked by the MaskedEditBox class as expected. 

 

Expected Result:

Since this control really only has 1 primary subcontrol (a fancy textbox). Event subscriptions to Click should subscribe to MaskedEditBoxElement.TextBoxItem.Click the += operator...

Should be fixed for MouseUp/Down and the all the other related key and mouse events.

 

Actual Result:

Subscriptions to Enter work on the MaskedEditBox class, but only subscriptions to MaskedEditBoxElement.TextBoxItem.Click work for Click events. This is highly confusing to the programmer whom is used to subscribing the standard Click event of a given control, and makes for unnecessarily complicated code and knowledge of the internal Element structure to make it work as expect like any other control.

 

Feature request:

It would be nice if there was also a "SelectionStart_MouseClick" property that works similar to SelectionStart but for Click events.

Also a EnableSelectionStart_MouseClick property with a default of false to maintain existing control behavior.

This allows the user to override the default cursor start position for Mouse Clicks. In the case above, the user cannot enter numbers unless they specifically click the start of the Mask; users find that confusing... 

The purpose of the above code is to be able to set the cursor start position "on-click", rather than only on Enter, which the existing SelectionStart property doesn't achieve.

Then we programmers could just set the properties and be done with it, and any subscriptions to the Click event would work as expected ->

public Form1() { InitializeComponent(); var customControl = new RadMaskedEditBoxV2() { MaskType = MaskType.Standard, Mask = "000000", PromptChar = '#', SelectionLength = 0, SelectionStart = 0, EnableSelectionStart_MouseClick = true, SelectionLength_MouseClick = 6, SelectionStart_MouseClick = 0 }; this.Controls.Add(customControl); }

 

 

 

public class RadMaskedEditBoxV2 : Telerik.WinControls.UI.RadMaskedEditBox { public RadMaskedEditBoxV2() : base() { this.EnableSelectionStart_MouseClick = false; this.MaskedEditBoxElement.TextBoxItem.Click += SelectionStartMouseClick_OnClick; } public new event EventHandler Click { add { base.MaskedEditBoxElement.TextBoxItem.Click += value; } remove { base.MaskedEditBoxElement.TextBoxItem.Click -= value; } } protected virtual void SelectionStartMouseClick_OnClick(object sender, EventArgs e) { if (EnableSelectionStart_MouseClick) { this.SelectionStart = SelectionStart_MouseClick; this.SelectionLength = SelectionLength_MouseClick; } } public int SelectionStart_MouseClick { get; set; } public int SelectionLength_MouseClick { get; set; } public bool EnableSelectionStart_MouseClick { get; set; } }

It would also allow the programmer to set the Enter and Click SelectionLengths separately.

 

Regards,

-Shawn.


6 comments
ADMIN
Dimitar
Posted on: 08 Apr 2019 10:01
Hello, 

The fix will be available in LIB Version 2019.1.415 scheduled for April 15th.

Added RadMaskedEditBoxElement Click EventHandler. 
Added the following RadMaskedEditBoxElement properties:
- EnableClickSelectionStart (Enables the SelectionStartMouseClick functionality)
- SelectionStartOnMouseClick (The selection start will be moved to this position when EnableClickSelectionStart is enabled)
- SelectionLengthOnMouseClick (The selection length will be set to this value when EnableClickSelectionStart is enabled)

Example of the new properties usage:
this.radMaskedEditBox1.MaskType = MaskType.Standard;
this.radMaskedEditBox1.Mask = "0000000000";
this.radMaskedEditBox1.PromptChar = '#';
 
this.radMaskedEditBox1.MaskedEditBoxElement.EnableClickSelectionStart = true;
this.radMaskedEditBox1.MaskedEditBoxElement.SelectionStartOnMouseClick = 2;
this.radMaskedEditBox1.MaskedEditBoxElement.SelectionLengthOnMouseClick = 4;

Regards,
Dimitar
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
ADMIN
Dimitar
Posted on: 14 Feb 2019 12:41
Hi Shawn,

We understand how this should work now. Thank for the clarification. 

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Shawn
Posted on: 13 Feb 2019 15:04

Basically, when the controls are first initialized with a mask and mask text, as it stands with the out-of-box experience any mouse click inside that control will cause the mouse to focus on the nearest char.

What the SelectionStartMouseClick property/event does is set focus to a custom SelectionStart (for mouse clicks).

However, this event fires on every mouse click, so once there is a value I default to the normal behavior (the out-of-box experience).

There may be some users who wish to retain the force SelectionStart, but I'd imagine those users are more rare.

In our case: our company has a 13 digit number, composed of 3 product identifiers and a date code.

I use the Mask to restrict it to just numbers, but the entry must always start from char index 0, not wherever they decide to click. This custom property/event give this functionality.

        [Category("Misc")]
        public int SelectionStart_MouseClick { get; set; }

        [Category("Misc")]
        public int SelectionLength_MouseClick { get; set; }

        [Category("Misc")]
        public bool EnableSelectionStart_MouseClick { get; set; }

 

Additionally, it fixes the Click handler so that it fires as expected for us programmers.

public new event EventHandler Click { add { base.MaskedEditBoxElement.TextBoxItem.Click += value; } remove { base.MaskedEditBoxElement.TextBoxItem.Click -= value; } }

 

 

I also do additional validation on KeyDown for the 3 ID's and DateCode, but that's a different topic.

Regards,

-Shawn.

ADMIN
Dimitar
Posted on: 13 Feb 2019 12:40
Hello Shawn,

I am confused about this because if the value is null or empty string, there will be nothing to select. Could you give us an example of how your users are using this? Can it be used for the underlying textbox or just with the masked edit box (I want to see if we can use this in a more general way)?

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Shawn
Posted on: 12 Feb 2019 19:11

I ended up having to add some logic so that it would only perform the SelectionStart_MouseClick feature when there isn't a value. That way the user can still set the cursor by mouse click on any char when there is a value inputted,

and it's virtual so the programmer can implement something else if they want to.

Just thought I'd mention it...

 

if (EnableSelectionStart_MouseClick)

{

      if (this.Value == null || (this.Value != null && this.Value.ToString().Length == 0))
     {
          this.SelectionStart = SelectionStart_MouseClick;
          this.SelectionLength = SelectionLength_MouseClick;
     }
}

ADMIN
Dimitar
Posted on: 06 Feb 2019 11:46
Hi Shawn,

Thank you for your feedback, I have approved the item and we will implement it when possible. I have updated your Telerik Points as well. 

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.