Articles in this section
Category / Section

How to provide a keyboard shortcut to programmatically open the primitive tab drop down in WinForms TabControlAdv?

1 min read

Keyboard settings

In TabControlAdv, to provide a keyboard shortcut to programmatically open the primitive tab drop down, it is not possible with default drop down. As a work around, we can add ContextMenuStrip and show it when we click the drop down or when we press Ctrl+A.

C#

private void tabControlAdv1_KeyDown(object sender, KeyEventArgs e)
{
   if (e.KeyData == (Keys.Control | Keys.A))
      this.contextMenuStrip1.Show(this.tabControlAdv1, new Point(this.tabControlAdv1.TabPrimitivesHost.Location.X, this.tabControlAdv1.TabPrimitivesHost.Location.Y+10));
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
   if(this.contextMenuStrip1.Items!=null)
      this.contextMenuStrip1.Items.Clear();
   foreach (TabPageAdv tabpageAdv in this.tabControlAdv1.TabPages)
   {
      this.contextMenuStrip1.Items.Add(tabpageAdv.Text);
   }
}

VB

Private Sub tabControlAdv1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles tabControlAdv1.KeyDown
   If e.KeyData = (Keys.Control Or Keys.A) Then
      Me.contextMenuStrip1.Show(Me.tabControlAdv1, New Point(Me.tabControlAdv1.TabPrimitivesHost.Location.X,
Me.tabControlAdv1.TabPrimitivesHost.Location.Y+10))
   End If
End Sub
Private Sub contextMenuStrip1_Opening(ByVal sender As Object, ByVal e As CancelEventArgs) Handles contextMenuStrip1.Opening
   If Me.contextMenuStrip1.Items IsNot Nothing Then
      Me.contextMenuStrip1.Items.Clear()
   End If
   For Each tabpageAdv As TabPageAdv In Me.tabControlAdv1.TabPages
      Me.contextMenuStrip1.Items.Add(tabpageAdv.Text)
   Next tabpageAdv
End Sub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied