)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to define custom shortcuts for BarItem in WinForms XPToolBar?

Platform: WinForms |
Control: XPToolbar |
Published Date: September 13, 2017 |
Last Revised Date: February 7, 2020 |
.NET Framework: 4
Tags: shortcut

Define custom shortcuts for BarItem

In XPToolBar, user can define set of pre-defined Short cut keys to its child items like Control, Shift etc. and it will help to select child items programmatically, when defined Key is pressed.

But there is no option to provide custom key combinations and it can be achieved by handling KeyDown event and using PerformClick function.

For Example, here we have created an example for Control + Key Up / Key Down key combinations.

C#

/// <summary>
/// KeyDown overrides
/// </summary>
protected override void OnKeyDown(KeyEventArgs e)
{
  if(e.KeyCode == Keys.Up && e.Modifiers == Keys.Control)
  {
    // To invoke Control + Key Up Baritem to be clicked programatically. 
    barItem1.PerformClick();
  }
  else if(e.KeyCode == Keys.Down && e.Modifiers == Keys.Control)
  {
    // To invoke Control + Key Down Baritem to be clicked programatically. 
    barItem2.PerformClick();
  }
  else if(e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
  {
    // To invoke Control + Key Enter Baritem to be clicked programatically. 
    barItem3.PerformClick();
  }
  base.OnKeyDown(e);
}
 
/// <summary>
/// Control + Key Up BarItem
/// </summary>
private void barItem1_Click(object sender, EventArgs e)
{
  MessageBox.Show("Control + Key Up is clicked");
}
 
/// <summary>
/// Control + Key Down BarItem
/// </summary>
private void barItem2_Click(object sender, EventArgs e)
{
  MessageBox.Show("Control + Key Down is clicked");
}
 
/// <summary>
/// Control + Enter BarItem
/// </summary>
private void barItem3_Click(object sender, EventArgs e)
{
  MessageBox.Show("Control + Enter Key is clicked");
}

VB

''' <summary>
''' KeyDown overrides
''' </summary>
Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
  If e.KeyCode = Keys.Up AndAlso e.Modifiers = Keys.Control Then
    ' To invoke Control + Key Up Baritem to be clicked programatically. 
    barItem1.PerformClick()
  ElseIf e.KeyCode = Keys.Down AndAlso e.Modifiers = Keys.Control Then
    ' To invoke Control + Key Down Baritem to be clicked programatically. 
    barItem2.PerformClick()
  ElseIf e.KeyCode = Keys.Enter AndAlso e.Modifiers = Keys.Control Then
    ' To invoke Control + Key Enter Baritem to be clicked programatically.
    barItem3.PerformClick()
  End If
  MyBase.OnKeyDown(e)
End Sub
 
''' <summary>
''' Control + Key Up BarItem
''' </summary>
Private Sub barItem1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles barItem1.Click
  MessageBox.Show("Control + Key Up is clicked")
End Sub
 
''' <summary>
''' Control + Key Down BarItem
''' </summary>
Private Sub barItem2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles barItem2.Click
  MessageBox.Show("Control + Key Down is clicked")
End Sub
 
''' <summary>
''' Control + Enter BarItem
''' </summary>
Private Sub barItem3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles barItem3.Click
  MessageBox.Show("Control + Enter Key is clicked")
End Sub

Screenshot

Show the custom shortcuts for BarItem

Samples:

C#: Custom Shortcuts for BarItem- C#

VB: Custom Shortcuts for BarItem - VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon