when use this.FormBorderStyle = FormBorderStyle.None ,ProcessCmdKey can not work?

3.6k views Asked by At

my code is:

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
    if (keyData == (Keys.LWin | Keys.M))
    {
        MessageBox.Show("LWin M");
        return true;
    }
    return base.ProcessCmdKey(ref msg, keyData);
}

private void Form1_Load(object sender, EventArgs e)
{
    this.FormBorderStyle = FormBorderStyle.None;
}

but the MessageBox.Show("LWin M"); never work,who can help me?thanks

update

the

MessageBos.Show("LWin M"); 

just for test ,the real code is:

this.WindowState = FormWindowState.Minimized;
2

There are 2 answers

0
Hans Passant On BEST ANSWER

This doesn't have anything to do with the FormBorderStyle, your code doesn't work when you omit the Load event as well. The Win + M shortcut keystroke is used by Windows before it sends it to a program. You can easily tell what it does, it minimizes the active window.

Never use the Windows key for your own shortcuts, you'll need to stick with Ctrl, Alt and Shift. Even using unassigned shortcuts is a Bad Idea, that will break in the next Windows version.

2
Steidl Stefan On

it depends what you want

if you want to check if "M" or "LWin" is pressed than try the following part:

if (keyData == Keys.LWin || keyData == Keys.M)