assigning function keys to toolstripbutton

  • Thread starter Thread starter Adam Sandler
  • Start date Start date
A

Adam Sandler

Hello,

Is it possible to assign a function key to a toolstripbutton? I don't
see the property for such an action in the properties for the
tsButton.

I have a "new" button on the toolstrip. I'd like F2 to fire the click
event handler. Is this possible?

Thanks!
 
If you are displaying text with the button, the button can have an
accelerator key shortcut, which you can specify by preceding the
appropriate letter in the text of the button with an ampersand.

If not, then as far as I know, you'd have to handle the keyboard input
elsewhere (such as the form's keyboard input methods) and map it to the
same action as the button (or just call PerformClick() method on the
button).

Pete

Yep... if one isn't using an accelerator key, which can very well
happen on buttons with graphics only, then the handler needs to be
assigned to the form.

I did some more searching and found this link: http://support.microsoft.com/kb/839201

And here is some pared down code based upon the MS example:

private void Form1_Load(object sender, System.EventArgs e)
{
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
MessageBox.Show("F2 pressed");
}
if (e.Control && e.KeyCode == Keys.P)
{
MessageBox.Show("print clicked");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top