Multiple modifiers (Ctrl+Shift) keydown handler in WinForm C#

public Form1()
{
    InitializeComponent();
    this.KeyPreview = true;
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    //Option A
    if (e.KeyCode == Keys.A && e.Modifiers == (Keys.Control | Keys.Shift))
    {
        this.Close();
    }

    //Option B
    if (e.Control && e.Shift && e.KeyCode == Keys.A)
    {
        this.Close();
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s