07-18-2005 09:44 PM
07-19-2005 12:12 AM
You must use Keys.Control instead of Keys.ControlKey and Keys.Shift instead of Keys.ShiftKey. Also, the Keys enumeration is attributed with FlagsAttribute, which means that the value may be a bitwise combination of enumeration values. For example, if you are explicitly checking Control.ModifierKeys to be equal to Keys.Control and both the CTRL and SHIFT modifier keys are pressed, the check will fail. Therefore, you should check to see if the Keys.Control or Keys.Shift bit is set in the Control.ModifierKeys value. Here is your example with the suggested modifications that will make it work:
private void wGraph_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if ((Control.ModifierKeys & (Keys.Control | Keys.Shift)) > 0) return; Point mPnt = new Point(e.X,e.Y); this.contextMenu1.Show(wGraph, mPnt); } }
- Elton
07-19-2005 11:52 PM
Thank you Elton. However, there occurs error.
If I use the code you suggested, I got the error message "System.Window.Forms.Keys Type cannot be converted into bool Type."
If I modify the code as follow,
if ((Control.ModifierKeys == Keys.Control) | (Control.ModifierKeys == Keys.Shift))
it works. But Shift + Ctrl Key generates unexpected response as you commented.
Do you have any idea?
Thanks you.
07-20-2005 12:09 AM
How did you test the code that I suggested? I copied and pasted the code into a new test project and it compiled with no errors or warnings and the application behaved as expected when I ran it.
- Elton
07-20-2005 02:45 AM
Sorry Elton. It's my typo.
Thank you very much.