Search Results for

    Show / Hide Table of Contents

    Creating a CustomButton

    This example provides information on creating custom commandbar controls like textbox, combobox, etc in RobotStudio.

    Solution

    1. Create a RibbonGroup(string, string)

      // Create a new group in the ribbon for our buttons
      RibbonGroup customControlGroup = new RibbonGroup("MyCustomControls", "MyCustom Control");
      
    2. Create CommandBarComboBox(string) control

      // Create combobox button control
      CommandBarComboBox buttonComboBox = new CommandBarComboBox("MyModule");
      buttonComboBox.Caption = "Procedure";
      buttonComboBox.Image = Image.FromFile(ReplaceWithValidImagePath);
      buttonComboBox.HelpText = "Select a procedure to execute from the dropdown list.";
      
      // Add event handler triggered by pressing the dropdown button.
      buttonComboBox.DropDown += BtnComboBox_DropDown;
      
    3. Create two CommandBarComboBoxItem(string) and add them to CommandBarComboBox

      // Add two items to the combo box for selection.
      CommandBarComboBoxItem cmbBoxItem1 = new CommandBarComboBoxItem("procedure1");
      CommandBarComboBoxItem cmbBoxItem2 = new CommandBarComboBoxItem("procedure2");
      buttonComboBox.Items.Add(cmbBoxItem1);
      buttonComboBox.Items.Add(cmbBoxItem2);
      
    4. Add EventHandler, and add the CommandBarComboBox to the ribbon group

      // Add event handler triggered by changing the selected item.
      buttonComboBox.SelectionChanged += BtnComboBox_SelectionChanged;
      buttonComboBox.SelectedIndex = 0;
      
      // Add control to ribbon group
      customControlGroup.Controls.Add(buttonComboBox);
      
    5. Create and set RibbonControlLayout

      // Set 'Small' layout for buttonComboBox
      RibbonControlLayout[] comboBoxLayout = new RibbonControlLayout[] { RibbonControlLayout.Small, RibbonControlLayout.Small };
      customControlGroup.SetControlLayout(buttonComboBox, comboBoxLayout);
      
    6. Add RibbonGroup to RibbonTab(string, string)

      // Add ribbon group to the active ribbon tab
      UIEnvironment.ActiveRibbonTab.Groups.Add(customControlGroup);
      

    Example

    This example provides information on creating custom command bar controls in RobotStudio.

    public void CustomControl()
    {
        // Begin UndoStep
        Project.UndoContext.BeginUndoStep("AddCustomControlButtons");
    
        try
        {
            // Create a new group in the ribbon for our buttons
            RibbonGroup customControlGroup = new RibbonGroup("MyCustomControls", "MyCustom Control");
    
            // Create combobox button control
            CommandBarComboBox buttonComboBox = new CommandBarComboBox("MyModule");
            buttonComboBox.Caption = "Procedure";
            buttonComboBox.Image = Image.FromFile(ReplaceWithValidImagePath);
            buttonComboBox.HelpText = "Select a procedure to execute from the dropdown list.";
    
            // Add event handler triggered by pressing the dropdown button.
            buttonComboBox.DropDown += BtnComboBox_DropDown;
    
            // Add two items to the combo box for selection.
            CommandBarComboBoxItem cmbBoxItem1 = new CommandBarComboBoxItem("procedure1");
            CommandBarComboBoxItem cmbBoxItem2 = new CommandBarComboBoxItem("procedure2");
            buttonComboBox.Items.Add(cmbBoxItem1);
            buttonComboBox.Items.Add(cmbBoxItem2);
    
            // Add event handler triggered by changing the selected item.
            buttonComboBox.SelectionChanged += BtnComboBox_SelectionChanged;
            buttonComboBox.SelectedIndex = 0;
            
            // Add control to ribbon group
            customControlGroup.Controls.Add(buttonComboBox);
    
            // Set 'Small' layout for buttonComboBox
            RibbonControlLayout[] comboBoxLayout = new RibbonControlLayout[] { RibbonControlLayout.Small, RibbonControlLayout.Small };
            customControlGroup.SetControlLayout(buttonComboBox, comboBoxLayout);
    
            // Create TextBox
            TextBox dataInputTextBox = new TextBox();
            dataInputTextBox.Enabled = true;
            dataInputTextBox.ReadOnly = false;
    
            // Set appearence
            dataInputTextBox.BackColor = Color.Black;
            dataInputTextBox.ForeColor = Color.SpringGreen;
            dataInputTextBox.TextAlign = HorizontalAlignment.Right;
            dataInputTextBox.Text = "Type here";
            dataInputTextBox.Width = 150;
    
            // Create a CommandBarCustomControl from the TextBox
            CommandBarCustomControl buttonTextBox = new CommandBarCustomControl("MyTextBox", dataInputTextBox);
            buttonTextBox.Caption = "Data";
            buttonTextBox.Image = Image.FromFile(ReplaceWithValidImagePath);
            buttonTextBox.HelpText = "Displays data typed";
    
            // Add control to ribbon group
            customControlGroup.Controls.Add(buttonTextBox);
    
            // Set 'Small' layout for buttonTextBox
            RibbonControlLayout[] textBoxlayout = new RibbonControlLayout[] { RibbonControlLayout.Small, RibbonControlLayout.Small };
            customControlGroup.SetControlLayout(buttonTextBox, textBoxlayout);
    
            // Add ribbon group to the active ribbon tab
            UIEnvironment.ActiveRibbonTab.Groups.Add(customControlGroup);
        }
        catch
        {
            Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
            throw;
        }
        finally
        {
            Project.UndoContext.EndUndoStep();
        }
    }
    static void BtnComboBox_SelectionChanged(object sender, EventArgs e)
    {
        //Called when index in comboxbox changes
    }
    static void BtnComboBox_DropDown(object sender, EventArgs e)
    {
        //Called when combobox is clicked
    }
    

    Required Namespaces

    ABB.Robotics.RobotStudio.Environment

    See Also

    • Creating DocumentWindow
    • Removing Button
    In this article
    Back to top Copyright © 2026 ABB Robotics