Solved

Exception on casting to HandledMouseEventArgs

Posted on 2012-12-21
3
617 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
ID: 38713509
It is actually a MouseEventArgs, not what you try to cast it to.
0
 
LVL 44

Accepted Solution

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

Author Comment

by:BlearyEye
ID: 38713623
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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