i have buttons and i would liek to make shortcuts from the keyboard to press them.

eg. btnAdd = CTRL+A

Set the button's UseMnemonic property to true and add an ampersand (&) just before the letter in the button's Text property you want to use for the hotkey. This will automatically assign the ALT-<key> to that button.

If you want to use CTRL or SHIFT you'll have to override the forms ProccessCmdKey method to look for the keys you want and then call the same method there that you would in your button handler, something like this:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    if (keyData == (Keys.Control | Keys.X)) {
        DoSomething();
        return true;
    }
    return base.ProcessCmdKey(ref msg, keyData);
}

private void button1_Click(object sender, EventArgs e) {
    DoSomething();
}

private void DoSomething() {
    MessageBox.Show("hi!");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.