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

RadMaskedEditBox MouseClick Event

4 Answers 148 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Bret
Top achievements
Rank 1
Bret asked on 25 Aug 2011, 04:38 PM
I'm trying to use the mouse click event on a RadMaskedEditBox, however nothing fires. Is this a bug?

thanks,

Bret

4 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 29 Aug 2011, 02:14 PM
Hello Bret,

Thank you for writing.

You can subscribe to the Click event of the RadMaskedEditBox using the following code:

this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.Click += new EventHandler(MaskedEditBoxElement_Click);

I hope this will help you. If you have further questions, I would be glad to help. All the best,
Ivan Petrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Bret
Top achievements
Rank 1
answered on 29 Aug 2011, 07:45 PM

I apologize for being vague and unclear. I need to assign the MouseClick event because I'm trying to capture a right mouse click on all labels, buttons, dropdownlists, and maskedEditBoxes. I'm able to use this with buttons, dropdownlists, and labels, but not the masked edit box.

If you consider the following code, There isn't MouseClick event for this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem so I've tried using the MouseUp event. However that fails with the following invalid cast type exception: "Unable to cast object of type 'Telerik.WinControls.UI.RadTextBoxItem' to type System.Windows.Forms.Control'." 

Now using this.radMaskedEditBox1.MouseClick will work, however the user has to click on the small border line to fire the event and isn't the desired action.

Lastly, I've tried this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.HostedControl.MouseClick, however left mouse clicks will fire the event, but not right.

This should be more helpful to the issue at hand.





private void Form1_Load(object sender, EventArgs e) 
//Runtime Error: Invalid Cast
this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.MouseUp += new MouseEventHandler(MouseClick); 
//Closest to working, but doesn't fire with right mouse click
this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.HostedControl.MouseClick += new MouseEventHandler(MouseClick); 
//Doesn't fire on the textbox, only the border
this.radMaskedEditBox1.MouseClick += new MouseEventHandler(MouseClick);
//Works perfectly
this.radLabel1.MouseClick += new MouseEventHandler(MouseClick); 
    
private void MouseClick(object sender, MouseEventArgs e) 
Control c = (Control)sender; 
this.radLabel1.Text = "Clicked On " + c.GetType() +
 
" using a " + (e.Button == MouseButtons.Right ? "Right Click" : "Left Click"); 
}
Thanks for the help,

Bret
0
Accepted
Bret
Top achievements
Rank 1
answered on 29 Aug 2011, 07:48 PM
this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.HostedControl.MouseUp += new MouseEventHandler(MouseClick);

Seems to work.

~Bret
0
Ivan Petrov
Telerik team
answered on 01 Sep 2011, 08:38 AM
Hello Bret,

I am glad you have found your way in this.

I am writing to confirm that this is the right approach and solution for your scenario.
I have marked your post as an answer, so others can use it.

Should you have further questions I would be glad to answer them.

All the best,
Ivan Petrov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
MaskedEditBox
Asked by
Bret
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Bret
Top achievements
Rank 1
Share this question
or