4 Answers, 1 is accepted
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 09 Nov 2010, 11:00 PM
Hi Eastern,
You need to create some events to mirror the ones that you want to handle.
1: In the user control, create some events that mirror the ones that you wish to handle.
2: Create event handlers for the RadMaskedEdit to handle the KeyPress , KeyDown, KeyUp, PreviewKewDown events
3: In the method body of these Event Handlers, raise your mirrored events.
A basic example is shown below:
and then in the form where you have the MaskedEditBox
hope that helps
Richard
You need to create some events to mirror the ones that you want to handle.
1: In the user control, create some events that mirror the ones that you wish to handle.
2: Create event handlers for the RadMaskedEdit to handle the KeyPress , KeyDown, KeyUp, PreviewKewDown events
3: In the method body of these Event Handlers, raise your mirrored events.
A basic example is shown below:
Imports System.ComponentModel Public Class MyMaskedEditBox Public Sub New() InitializeComponent() End Sub ' Some of the propeties will exposed here ' Some of the methods may be exposed here <Description("The event for the controls keydown event")> _ <Category("MyMaskedEdit Events")> _ Public Event MaskedEditKeyDown As KeyEventHandler <Description("The event for the controls keypress event")> _ <Category("MyMaskedEdit Events")> _ Public Event MaskedEditKeyPress As KeyPressEventHandler <Description("The event for the controls keyup event")> _ <Category("MyMaskedEdit Events")> _ Public Event MaskedEditKeyUp As KeyEventHandler Private Sub RadMaskedEditBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RadMaskedEditBox1.KeyDown RaiseEvent MaskedEditKeyDown(sender, e) ' Handle MaskedEditKeyDown where you are using this this user control End Sub Private Sub RadMaskedEditBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RadMaskedEditBox1.KeyPress RaiseEvent MaskedEditKeyPress(sender, e) ' Handle MaskedEditKeyPress where you are using this this user control End Sub Private Sub RadMaskedEditBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RadMaskedEditBox1.KeyUp RaiseEvent MaskedEditKeyUp(sender, e) ' Handle MaskedEditKeyUp where you are using this this user control End Sub End Classand then in the form where you have the MaskedEditBox
Private Sub MyMaskedEditBox1_MaskedEditKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyMaskedEditBox1.MaskedEditKeyDown ' handle something here End Subhope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 09 Nov 2010, 11:24 PM
Hello Eastern,
Please accept my apologies. I missed that this was an inherited control.
Please see this forum post to see about subscribing to these events.
Best regards,
Richard
Please accept my apologies. I missed that this was an inherited control.
Please see this forum post to see about subscribing to these events.
Best regards,
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 10 Nov 2010, 12:09 AM
Hello,
Here is a small sample for you too.
and in the form where the control is:
Hope this helps
richard
Here is a small sample for you too.
Imports System.ComponentModel Public Class MyMaskedEditControl Inherits Telerik.WinControls.UI.RadMaskedEditBox <Category("MyMaskedEdit events")> _ Public Event MaskedEditKeyPress As KeyPressEventHandler <Category("MyMaskedEdit events")> _ Public Event MaskedEditPreviewKeyDown As PreviewKeyDownEventHandler Public Sub New() InitializeComponent() AddHandler MyBase.MaskedEditBoxElement.TextBoxItem.KeyPress, AddressOf MyMaskedEditBox_KeyPress AddHandler MyBase.MaskedEditBoxElement.TextBoxItem.PreviewKeyDown, AddressOf MyMaskedEditBox_PreviewKeyDown End Sub Private Sub MyMaskedEditBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) RaiseEvent MaskedEditKeyPress(sender, e) End Sub Private Sub MyMaskedEditBox_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) RaiseEvent MaskedEditPreviewKeyDown(sender, e) End SubEnd Classand in the form where the control is:
Private Sub MyMaskedEditControl1_MaskedEditPreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles MyMaskedEditControl1.MaskedEditPreviewKeyDown MessageBox.Show(e.KeyValue.ToString()) End SubPrivate Sub MyMaskedEditControl1_MaskedEditKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyMaskedEditControl1.MaskedEditKeyPress MessageBox.Show(e.KeyChar.ToString()) End SubHope this helps
richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 10 Nov 2010, 06:54 AM
Hello guys,
The problem here is that when the keydown, keypressed and other events are being fired from the MaskedEditBoxElement not from the control itself, so you can use the following:
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
The problem here is that when the keydown, keypressed and other events are being fired from the MaskedEditBoxElement not from the control itself, so you can use the following:
this.customMaskedEditBox1.MaskedEditBoxElement.KeyPress += new KeyPressEventHandler(MaskedEditBoxElement_KeyPress);void MaskedEditBoxElement_KeyPress(object sender, KeyPressEventArgs e){ MessageBox.Show("KeyPress called");}Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga