how to prevent keydown e.alt from opening an irrelevant drop down menu?

48 views Asked by At
private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Shift)
        {
            PDiff = 20;
        }
        if (e.Control)
        {
            PDiff = 30;
        }
        if (e.Alt)
        {
            PDiff = 40; //opens up a drop down menu if not pressed first

        }
    }

ok so my program is 100% complete, but I'm having a glitch where half the time e.Alt does what I need it to do and the other half of the time it opens up an irrelevant drop down menu. The irrelevant drop down menu usually appears when I press shift or control before alt.

(The menu is Restore > Move > Size > Minimize > Maximize > Close btw)

I was told that changing the order of the code would help, but it either didn't work or I didn't understand what they meant.

Any help would be appreciated!

1

There are 1 answers

0
Zoltán Tamási On

In cases like this, you should set the KeyEventArgs.Handled boolean property to true. With that you can indicate that the default behavior should be omitted.

I'm not completely sure that it will solve this exact problem though, as I don't have the chance to test it currently.