471,330 Members | 1,906 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

assigning function keys to toolstripbutton

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!
Jun 27 '08 #1
2 8968
On Tue, 03 Jun 2008 22:26:04 -0700, Adam Sandler <co****@excite.comwrote:
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.
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
Jun 27 '08 #2
On Jun 4, 12:00 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
>
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_Ke yDown);
}

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");
}
}
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Don W. | last post: by
3 posts views Thread by Armando | last post: by
3 posts views Thread by Dennis C. Drumm | last post: by
4 posts views Thread by One | last post: by
4 posts views Thread by Broeisi | last post: by
9 posts views Thread by Wingot | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.