assigning function keys to toolstripbutton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Sandler

    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!
  • Peter Duniho

    #2
    Re: assigning function keys to toolstripbutton

    On Tue, 03 Jun 2008 22:26:04 -0700, Adam Sandler <corn29@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

    Comment

    • Adam Sandler

      #3
      Re: assigning function keys to toolstripbutton

      On Jun 4, 12:00 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.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(obje ct sender, System.EventArg s e)
      {
      this.KeyDown += new
      System.Windows. Forms.KeyEventH andler(this.For m1_KeyDown);
      }

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

      Comment

      Working...