RadMaskedEditBox MouseClick Event

5 posts, 1 answers
  1. Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 25 Aug 2011 Link to this post

    I'm trying to use the mouse click event on a RadMaskedEditBox, however nothing fires. Is this a bug?

    thanks,

    Bret
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Aug 2011 Link to this post

    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 >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 29 Aug 2011 Link to this post

    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
  5. Answer
    Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 29 Aug 2011 Link to this post

    this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.HostedControl.MouseUp += new MouseEventHandler(MouseClick);

    Seems to work.

    ~Bret
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready