ComponentOne Menus and Toolbars for WinForms
Menus and Toolbars for WinForms Task-Based Help / Context Menu Tasks / Adding a ContextMenu to a DockingTab
In This Topic
    Adding a ContextMenu to a DockingTab
    In This Topic

    Complete the following steps to add a C1ContextMenu control to a C1DockingTab control.

    1. Locate the C1ContextMenu control in your Toolbox and double-click the control to add it to your Component Tray. A C1CommandHolder will also be added to the Component Tray.
    2. Use the C1ContextMenu smart tag to open the C1ContextMenu Tasks Menu. Select Add Item from the Tasks Menu to add an item to the C1ContextMenu. Add two more items to the menu.
    3. Place a C1DockingTab control on the form and open the C1DockingTab Context Menu. Select Add Page from the context menu. Add several pages to the C1DockingTab.
      Select the C1DockingTab control on your form to view the properties. Click the Events button and locate the MouseClick event. Insert c1DockingTab1_MouseClick to create the MouseClick event.
    4. Right-click on the form and select View Code from the list. Insert the following code after the InitializeComponent() method:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub c1DockingTab1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
          If (e.Button = System.Windows.Forms.MouseButtons.Left) Then
              If (e.X > Me.c1DockingTabPage1.Location.X) Then
                  c1ContextMenu1.ShowContextMenu(Me.c1DockingTab1, New Point(e.X, e.Y))
              Else
                  Me.c1DockingTab1.ContextMenu = Nothing
              End If
          End If
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void c1DockingTab1_MouseClick(object sender, MouseEventArgs e)
          {
              if (e.Button == System.Windows.Forms.MouseButtons.Left)
              {
                  if (e.X > this.c1DockingTabPage1.Location.X)
                  {                    
                      c1ContextMenu1.ShowContextMenu(this.c1DockingTab1, new Point(e.X, e.Y));
                  }
                  else
                      this.c1DockingTab1.ContextMenu = null;
              }
          }
      
    5. Press F5 to run your application. Note that when you click on a tab, the C1ContextMenu opens:
      Application UI
    See Also