Exception on casting to HandledMouseEventArgs

BlearyEye
BlearyEye used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
It is actually a MouseEventArgs, not what you try to cast it to.
Freelance programmer / Consultant
Commented:
ps.  The HandledMouseEventArgs is (according to my help file) only for a mouse wheel event.

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial