Solved

Exception on casting to HandledMouseEventArgs

Posted on 2012-12-21
3
608 Views
Last Modified: 2012-12-22
This should be simple but ... I have this event handler on a textbox to ignore right mouse clicks. When it executes I get InvalidCastException on the 3rd line.

        private void txtUserName_MouseDown(object sender, MouseEventArgs e) {
            if (e.Button == System.Windows.Forms.MouseButtons.Right) {
                HandledMouseEventArgs eh = (HandledMouseEventArgs)e;
                eh.Handled = true;
            }
        }

Open in new window

Per http://stackoverflow.com/questions/4264579/how-to-prevent-mouse-scroll-in-toolstripcombobox and other examples, this ought to work. Instead, I get the exception. Ideas?
0
Comment
Question by:BlearyEye
  • 2
3 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
It is actually a MouseEventArgs, not what you try to cast it to.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
Comment Utility
ps.  The HandledMouseEventArgs is (according to my help file) only for a mouse wheel event.
0
 
LVL 1

Author Comment

by:BlearyEye
Comment Utility
I see that now... so, I want to ignore right-click for this control. Is there another way to do it? MouseEventArgs doesn't support a .Handled property.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 3 35
XML to SQL Table using c# 5 42
LINQ question 7 20
Word Template Mail merge with vb.net 4 37
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now