locked
How do i assign "+" keyboard key to my add button? RRS feed

  • Question

  • How do i assign "+" sign keyboard key to my add button? in c# 
    Wednesday, April 16, 2014 9:04 PM

Answers

  • If you want to raise the button's Click event programmatically when the + key is pressed, you could handle the KeyDown event of the form:

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                this.KeyPreview = true;
                this.KeyDown += Form1_KeyDown;
            }
    
            void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Oemplus)
                {
                    buttonAdd.PerformClick();
                }
            }
    
            private void buttonAdd_Click(object sender, EventArgs e)
            {
                //handle click...
            }
        }
    

    Wednesday, April 16, 2014 9:34 PM