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.