How to insert command key in C #

0

Someone could help me, I wanted to create a command with the keys CTRL + Z or something like that to save, edit or send data as a shortcut to a button created in Form .

    
asked by anonymous 30.06.2017 / 19:05

1 answer

2
  • Change the KeyPreview of form as true .

  • Set the actions for the shortcuts in the #

    Example:

    private void MainForm_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.Z)            
            Desfazer();            
    
        if (e.Control && e.KeyCode == Keys.S)
            Salvar();            
    
        //Assim por diante
    }
    
  • You can also override the KeyDown method.

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 
    {
        if (keyData == (Keys.Control | Keys.S)) 
        {
            Salvar();
            return true;
        }
    
        return base.ProcessCmdKey(ref msg, keyData);
    }
    
        
    30.06.2017 / 19:11