Removing a Button
This example outlines the steps to remove an existing CommandBarButton from a RibbonGroup and RibbonTab in RobotStudio. It builds upon the example provided in Creating a Button, assuming that MyFirstButton has already been created and added to the UI. This example does not require a station.
Solution
Get RibbonTab
// Find and get the specified RibbonTab by its unique ID RibbonTab ribbonTab = UIEnvironment.RibbonTabs["MyTab"];
Remove MyFirstButton from RibbonGroup and RibbonTab
// Remove button with ID "MyFirstButton" from RibbonGroup "MyButtons" ribbonTab.Groups["MyButtons"].Controls.Remove("MyFirstButton");
Example
public void RemoveButton()
{
// Begin UndoStep
Project.UndoContext.BeginUndoStep("RemoveButton");
try
{
// Find and get the specified RibbonTab by its unique ID
RibbonTab ribbonTab = UIEnvironment.RibbonTabs["MyTab"];
// Remove button with ID "MyFirstButton" from RibbonGroup "MyButtons"
ribbonTab.Groups["MyButtons"].Controls.Remove("MyFirstButton");
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.