$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
RibbonBar Control for Windows Forms
Create innovative user interfaces and build Office 2007 and 2010 ribbon bar design
Home > WinForms UI Controls > User Manual > Add/Remove Groups and Buttons in C# in C#

C# Add and Remove Groups and Buttons of RibbonBar Control

KetticRibbonBar allows the users to add and remove RibbonBar groups and buttons at design time, as well as at run time in C# template projects. The RibbonBar groups and buttons adding and removing at run time in C# require the use of the appropriate objects and collections. In this article, we are going through the process of adding and removing RibbonBar groups and buttons in C#.NET application at run time.

C# Add a Button to RibbonBar group

When the designers of user interface of RibbonBar need to add a button to RibbonBar group in C# project at run time, they need to create a new KetticButtonElement and add the element to the KetticRibbonBarGroup.Items collection. The C# code below demonstrates the process of adding a button to KetticRibbonBarGroup at runtime.

KetticButtonElement ketticButtonElement1 = new KetticButtonElement();
ketticButtonElement1.Text = "Button A";
ketticRibbonBarGroup1.Items.Add(ketticButtonElement1);
Similarly, KetticRibbonBar control provides the AddRange method for the designers to add multiple buttons to KetticRibbonBarGroup at once at run time.

KetticButtonElement ketticButtonElement2 = new KetticButtonElement();
KetticButtonElement ketticButtonElement3 = new KetticButtonElement();
ketticButtonElement2.Text = "Button B";
ketticButtonElement3.Text = "Button C";
ketticRibbonBarGroup1.Items.AddRange(new KetticItem[] { ketticButtonElement2, ketticButtonElement3 });

C# Remove a Button from RibbonBar group

If the designers want to remove a button from the KetticRibbonBar group, they need to call the Remove method of KetticRibbonBarGroup.Items collection and specify the KetticButtonElement that will be deleted.

KetticButtonElement elementToRemove = (KetticItem)ketticRibbonBarGroup1.Items[1] as KetticButtonElement;
ketticRibbonBarGroup1.Items.Remove(elementToRemove);
KetticRibbonBar control offers the RemoveAt method for the designers to remove a button by index. The C# code below shows the process of removing a button from KetticRibbonBarGroup by index.

ketticRibbonBarGroup1.Items.RemoveAt(1);

C# Add a Button Group with Buttons

KetticRibbonBar control allows the users to add a button group with buttons to a RibbonBar group. To achieve this, we need to create a new KetticRibbonBarButtonGroup object and customize the properties of this object, add the objects to the KetticButtonBarGroup.Items collection, and then add the KetticButtonBarGroup object to the KetticRibbonBarGroup.Items collection. The following C# code shows how to achieve this.

KetticRibbonBarButtonGroup ketticRibbonBarButtonGroup1 = new KetticRibbonBarButtonGroup();
ketticRibbonBarButtonGroup1.Orientation = System.Windows.Forms.Orientation.Horizontal;
ketticRibbonBarButtonGroup1.MinSize = new System.Drawing.Size(22, 22);
ketticRibbonBarButtonGroup1.ShowBorder = true;
KetticButtonElement ketticButtonElement4 = new KetticButtonElement();
KetticButtonElement ketticButtonElement5 = new KetticButtonElement();
ketticButtonElement4.Text = "Button A";
ketticButtonElement5.Text = "Button B";
ketticRibbonBarButtonGroup1.Items.AddRange(new KetticItem[] { ketticButtonElement1, ketticButtonElement2 });
ketticRibbonBarGroup1.Items.Add(ketticRibbonBarButtonGroup1);
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls