4
Answers

Keys in C#

Zuber Kazi

Zuber Kazi

13y
4.2k
1
Hello everyone,
        I am developing a windows application in C#.
On form_keydown event
             if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
this is working properly
but i want to save data on ctrl+s
i tried for
                 if (e.KeyCode == Keys.control + Keys.S)

but it throws an error
please help me out.

Regards,
Zuber I. Kazi.
Answers (4)
0
kishore kumar
NA 58 3.9k 13y
Try this

//83 Key code for 'S'
If(e.Control && e.KeyValue==83)
{
}

Regards,
Kishore
Accepted
0
Zuber Kazi
NA 40 29.6k 13y
Thanx Kishore Kumar
but it again shows an error
"Error    1    Operator '==' cannot be applied to operands of type 'System.Windows.Forms.Keys' and 'int'   "
0
Sam Hobbs
NA 28.7k 1.3m 13y
You should create a menu item for saving data. If you do that then you just set the shortcut key for it and then you don't have to make things difficult as you are doing here.
0
kishore kumar
NA 58 3.9k 13y
Try this
//83 Key code for 'S'
If(e.Control && e.KeyCode==83)
{

}

Regards,
Kishore