Creating a SplitButton
This example provides information on creating split buttons in RobotStudio.
Solution
Create ribbon group for the split button
RibbonGroup ribbonGroup = new RibbonGroup("MySplitButtonsGroup", "My Split Button");
Create button
CommandBarButton button = new CommandBarButton("MyButton", "My main button"); button.HelpText = "Click here for the main action"; button.DefaultEnabled = true;
Create CommandBarGalleryPopup button
CommandBarGalleryPopup galleryPopup = new CommandBarGalleryPopup("MyGalleryPopup", "My Gallery PopUp"); galleryPopup.Image = Image.FromFile(ReplaceWithValidImagePath); galleryPopup.Enabled = CommandBarPopupEnableMode.Enabled; galleryPopup.HelpText = "Choose an option";
Assign the button to be displayed on the top portion of button, and set text position and size
galleryPopup.ClickButton = button; galleryPopup.GalleryTextPosition = GalleryTextPosition.Right; galleryPopup.GalleryItemSize = new System.Drawing.Size(120, 15);
Add button to gallery control
galleryPopup.GalleryControls.Add(button);
Add gallery control to ribbon group
ribbonGroup.Controls.Add(galleryPopup);
Add ribbon group to ribbon tab
UIEnvironment.ActiveRibbonTab.Groups.Add(ribbonGroup);
Example
This example provides information on creating split buttons in RobotStudio.
public void SplitButton()
{
// Begin UndoStep
Project.UndoContext.BeginUndoStep("SplitButtons");
try
{
// Create a ribbon group for buttons
RibbonGroup ribbonGroup = new RibbonGroup("MySplitButtonsGroup", "My Split Button");
// Create button
CommandBarButton button = new CommandBarButton("MyButton", "My main button");
button.HelpText = "Click here for the main action";
button.DefaultEnabled = true;
// Create gallery pop up
CommandBarGalleryPopup galleryPopup = new CommandBarGalleryPopup("MyGalleryPopup", "My Gallery PopUp");
galleryPopup.Image = Image.FromFile(ReplaceWithValidImagePath);
galleryPopup.Enabled = CommandBarPopupEnableMode.Enabled;
galleryPopup.HelpText = "Choose an option";
// Assign buttonSplit to the gallery pop up, displayed on the top portion of the split button
galleryPopup.ClickButton = button;
// Set text position and size of gallery
galleryPopup.GalleryTextPosition = GalleryTextPosition.Right;
galleryPopup.GalleryItemSize = new Size(120, 15);
// Add button to gallery control
galleryPopup.GalleryControls.Add(button);
// Add gallery control to ribbon group
ribbonGroup.Controls.Add(galleryPopup);
// Add ribbon group to ribbon tab
UIEnvironment.ActiveRibbonTab.Groups.Add(ribbonGroup);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.