# Getting Started with WinForms SplitButton

This article shows how you can start using **RadSplitButton**.

## Adding Telerik Assemblies Using NuGet

To use **RadSplitButton** when working with NuGet packages, install the `Telerik.UI.for.WinForms.AllControls` package. The [package target framework version may vary](https://www.telerik.com/products/winforms/documentation/visual-studio-integration/available-nugets).

Read more about NuGet installation in the [Install using NuGet Packages](https://www.telerik.com/products/winforms/documentation/installation-and-upgrades/install-using-nuget) article.

> tip With the 2025 Q1 release, the Telerik UI for WinForms has a new licensing mechanism. You can learn more about it [here](https://www.telerik.com/products/winforms/documentation/licensing/license-key).

## Adding Assembly References Manually

When dragging and dropping a control from the Visual Studio (VS) Toolbox onto the Form Designer, VS automatically adds the necessary assemblies. However, if you're adding the control programmatically, you'll need to manually reference the following assemblies:

* **Telerik.Licensing.Runtime**
* **Telerik.WinControls**
* **Telerik.WinControls.UI**
* **TelerikCommon**

The Telerik UI for WinForms assemblies can be install by using one of the available [installation approaches](https://www.telerik.com/products/winforms/documentation/installation-and-upgrades/installing-on-your-computer).

## Defining the RadSplitButton

You can add **RadSplitButton** either at design time or at run time:

### Design Time

1. To add a **RadSplitButton** to your form, drag a **RadSplitButton** from the toolbox onto the surface of the form designer.
2. Like a standard button, you can control the displayed text by setting the **Text** property.
3. Unlike a standard button, **RadSplitButton** displays drop-down items when clicked. So handling the **Click** event of this button is not appropriate. Instead, work directly with the events for each item.

### Run Time

To programmatically add a **RadSplitButton** to a form, create a new instance of a **RadSplitButton**, and add it to the form **Controls** collection.

#### Adding a RadSplitButton at runtime

```C#
RadSplitButton splitButton = new RadSplitButton();
splitButton.Text = "Fruits";
RadMenuItem item1 = new RadMenuItem("Orange");
splitButton.Items.Add(item1);
RadMenuItem item2 = new RadMenuItem("Lemon");
splitButton.Items.Add(item2);
RadMenuItem item3 = new RadMenuItem("Banana");
splitButton.Items.Add(item3);
this.Controls.Add(splitButton);
```

```VB.NET
Dim splitButton As New RadSplitButton()
splitButton.Text = "Fruits"
Dim item1 As New RadMenuItem("Orange")
splitButton.Items.Add(item1)
Dim item2 As New RadMenuItem("Lemon")
splitButton.Items.Add(item2)
Dim item3 As New RadMenuItem("Banana")
splitButton.Items.Add(item3)
Me.Controls.Add(splitButton)
```

### Working with RadSplitButton Items

The heart of **RadSplitButton** is the **Items** collection. This collection defines the menu items that appear when the **RadSplitButton** is clicked. There are two ways to add items to a **RadSplitButton**.

### Adding Items at Design-time in the UI

To add menu items at design-time, please refer to the [Design Time](https://www.telerik.com/products/winforms/documentation/controls/buttons/splitbutton/design-time) help article.

### Adding Items at Run Time in Code

You can also add items to **RadSplitButton** in code at run time. The following example code illustrates programmatically adding a **RadMenuItem** to your button.

#### Adding a RadMenuItem

```C#
private void Form1_Load(object sender, EventArgs e)
{
    RadMenuItem myRadMenuItem = new RadMenuItem();
    myRadMenuItem.Text = "My New Item";
    myRadMenuItem.Click += new EventHandler(myRadMenuItem_Click);
    radSplitButton1.Items.Add(myRadMenuItem);
}

void myRadMenuItem_Click(object sender, EventArgs e)
{
    MessageBox.Show((sender as RadMenuItem).Text);
}
```

```VB.NET

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim myRadMenuItem As New RadMenuItem()
    myRadMenuItem.Text = "My New Item"
    AddHandler myRadMenuItem.Click, AddressOf myRadMenuItem_Click
    radSplitButton1.Items.Add(myRadMenuItem)
End Sub

Sub myRadMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show((TryCast(sender, RadMenuItem)).Text)
End Sub

```

Create item hierarchies in code by adding new **RadMenuItem** objects to the **Items** collection of your existing **RadMenuItem**.

#### Adding a sub item

```C#
private void Form1_Load(object sender, EventArgs e)
{
    radSplitButton1.Items.Add(new RadMenuItem("AAA"));

    RadMenuItem mySubMenuItem = new RadMenuItem();
    mySubMenuItem.Text = "Submenu Item";
    mySubMenuItem.Click += new EventHandler(mySubMenuItem_Click);
    RadMenuItem mainItem = radSplitButton1.Items[0] as RadMenuItem;
    mainItem.Items.Add(mySubMenuItem);
}

void mySubMenuItem_Click(object sender, EventArgs e)
{
    MessageBox.Show((sender as RadMenuItem).Text);
}
```

```VB.NET

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mySubMenuItem As New RadMenuItem()
    mySubMenuItem.Text = "Submenu Item"
    AddHandler mySubMenuItem.Click, AddressOf mySubMenuItem_Click
    Dim mainItem As RadMenuItem = TryCast(radSplitButton1.Items(0), RadMenuItem)
    mainItem.Items.Add(mySubMenuItem)
End Sub

Sub mySubMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show((TryCast(sender, RadMenuItem)).Text)
End Sub

```

### Displaying Images with Items

You can display images as well as text on your menu items.

![WinForms RadSplitButton Image Items](https://www.telerik.com/products/winforms/documentation/assets/2d967c47386b4609d6e0d0168d9725e6/buttons-splitbutton-working-with-radsplitbutton-items003.png)

To add an image to your menu item, click in the **Image** property of the **RadMenuItem**, and then click the ellipsis button to launch the **Select Resource** dialog.

![WinForms RadSplitButton RadMenuItem Image Text](https://www.telerik.com/products/winforms/documentation/assets/85344abc075d4a9a4a8d11d6e0791dde/buttons-splitbutton-working-with-radsplitbutton-items004.png)

From this dialog you can select an image file from a project resource file or from an image resource on your local hard drive.

### Using the Click Event

To handle the **Click** event of **RadMenuItems** on the drop down menu, locate the **RadMenuItem** in the drop down list in the Properties window of the Windows Form designer. Click the events button, then double-click the **Click** event to generate an event handler. Fill in the details of your event-handling code.

### Setting the Default Item

The default item is the item whose **Click** event is triggered by the user pressing the button, instead of choosing from the menu. The **DefaultItem** can be assigned in code:

#### Assigning the default item

```C#
radSplitButton1.DefaultItem = mainItem;
```

```VB.NET

radSplitButton1.DefaultItem = mainItem

```

## Telerik UI for WinForms Learning Resources

* [Telerik UI for WinForms SplitButton Component](https://www.telerik.com/products/winforms/buttons.aspx)
* [Getting Started with Telerik UI for WinForms Components](https://docs.telerik.com/devtools/winforms/getting-started/first-steps)
* [Telerik UI for WinForms Setup](https://docs.telerik.com/devtools/winforms/installation-and-upgrades/installing-on-your-computer)
* [Telerik UI for WinForms Converter](https://www.telerik.com/products/winforms/documentation/ai-coding-assistant/converter/converter)
* [Telerik UI for WinForms Visual Studio Templates](https://docs.telerik.com/devtools/winforms/visual-studio-integration/visual-studio-templates)
* [Deploy Telerik UI for WinForms Applications](https://docs.telerik.com/devtools/winforms/deployment-and-distribution/application-deployment)
* [Telerik UI for WinForms Virtual Classroom(Training Courses for Registered Users)](https://learn.telerik.com/learn/course/external/view/elearning/17/telerik-ui-for-winforms)
* [Telerik UI for WinForms License Agreement)](https://www.telerik.com/purchase/license-agreement/winforms-dlw-s)
