Bunifu Toggle Switch
Easily add stylish ON and OFF states to your user interface using Bunifu Toggle Switch.

Overview

Bunifu Toggle Switch Button control is a rich two-state button, perfect for when you need to provide the user with an option to flip a switch. It has highly customizable toggle settings and features such as animations that will blend into the look and feel of your WinForms application.

Getting Started

This section describes how to include Bunifu Toggle Switches in both the design and coding environments.

Adding Bunifu Toggle Switch at design time

Bunifu Toggle Switch can be added to the form by simply locating or searching BunifuToggleSwitch control in your toolbox and dragging it onto your form. You can then customize using the custom properties provided. We'll discuss the various features in greater detail later in this documentation.

Adding Bunifu Toggle Switch at Runtime

To add Bunifu Toggle Switch at runtime we will have to use the Form's Load event handler, where we'll create an instance of BunifuToggleSwitch control and add it to the form as shown below.:
C#
VB.NET
1
private void Form1_Load(object sender, EventArgs e)
2
{
3
//Instatiate Bunifu Toggle Switch control using Bunifu.UI.WinForms
4
BunifuToggleSwitch toggleSwitch = new BunifuToggleSwitch();
5
//Set the location for the toggle switch
6
toggleSwitch.Location = new Point(330, 170);
7
//set the thumb color for the switch on toggle state on
8
toggleSwitch.ToggleStateOn.BackColorInner = Color.White;
9
//set the back color for the switch on toggle state on
10
toggleSwitch.ToggleStateOn.BackColor = Color.DodgerBlue;
11
//add the toggle switch to the form
12
this.Controls.Add(toggleSwitch);
13
}
Copied!
1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
2
'Instatiate Bunifu Toggle Switch control using Bunifu.UI.WinForms
3
Dim toggleSwitch As New BunifuToggleSwitch()
4
'Set the location for the toggle switch
5
toggleSwitch.Location = New Point(330, 170)
6
'set the thumb color for the switch on toggle state on
7
toggleSwitch.ToggleStateOn.BackColorInner = Color.White
8
'set the back color for the switch on toggle state on
9
toggleSwitch.ToggleStateOn.BackColor = Color.DodgerBlue
10
'add the toggle switch to the form
11
Me.Controls.Add(toggleSwitch)
12
End Sub
13
Copied!
Let's deep dive and get insights into the available properties on Bunifu Toggle Switch.

Animation

This property makes sliding and a bounce effect to the switch when switching states. It sets a numeric value that sets the animation speed.

Checked

This property sets a boolean value, which determines the toggle state of the control. When the property is set to true, it sets the toggle switch in an On state.
The property is used in conjuction with the CheckedChanged event which fires whenever the toggle state changes. Here's a code snippet that displays a snackbar whenever the state changes
C#
VB.NET
1
private void bunifuToggleSwitch1_CheckedChanged(object sender, Bunifu.UI.WinForms.BunifuToggleSwitch.CheckedChangedEventArgs e)
2
{
3
if (e.Checked)
4
{
5
bunifuSnackbar1.Show(this, "Option set to On!");
6
}
7
else
8
{
9
bunifuSnackbar1.Show(this, "Option set to Off!");
10
}
11
}
Copied!
1
Private Sub bunifuToggleSwitch1_CheckedChanged(ByVal sender As Object, ByVal e As Bunifu.UI.WinForms.BunifuToggleSwitch.CheckedChangedEventArgs)
2
If e.Checked Then
3
bunifuSnackbar1.Show(Me, "Option set to On!")
4
Else
5
bunifuSnackbar1.Show(Me, "Option set to Off!")
6
End If
7
End Sub
8
Copied!

ThumbMargin

This property sets a padding value for the thumb or switch, determining the space between the thumb and the toggle switch box border. By default, the value is set to 3.

ToggleStateOn Properties

The on-state properties can be easily accessed under the ToggleStateOn category in the properties pane.
Here's a detailed description of the properties:

1. BackColor

This property allows you to get or set the background color of the toggle switch box. It's compatible with the use of RGB and HEX color values.

2. BackColorInner

This property allows you to get or set the background color of the switch.

3. BorderColor

This property allows you to get or set the toggle switch box border color.

4. BorderColorInner

This property allows you to set the border color of the switch.

5. BorderRadius

This property allows you to apply the radius value for the toggle switch box border edges. By increasing the value, the edges become more rounded.

6. BorderRadiusInner

This property allows you to apply the radius value for the switch edges. By increasing the value, the edges become more rounded.

7. BorderThickness

This property allows you to set a thickness value for the toggle switch box border. By increasing the value, the border becomes thicker.

8. BorderThicknessInner

This property allows you to set the thickness value of the switch. By increasing the value, the border becomes thicker.

ToggleStateOff Properties

The off-state properties can be easily accessed under the ToggleStateOff category in the properties pane.
Here's a detailed description of the properties:

1. BackColor

This property allows you to get or set the background color of the toggle switch box. It's compatible with the use of RGB and HEX color values.

2. BackColorInner

This property allows you to get or set the background color of the switch.

3. BorderColor

This property allows you to get or set the toggle switch box border color.

4. BorderColorInner

This property allows you to set the border color of the switch.

5. BorderRadius

This property allows you to apply the radius value for the toggle switch box border edges. By increasing the value, the edges become more rounded.

6. BorderRadiusInner

This property allows you to apply the radius value for the switch edges. By increasing the value, the edges become more rounded.

7. BorderThickness

This property allows you to set a thickness value for the toggle switch box border. By increasing the value, the border becomes thicker.

8. BorderThicknessInner

This property allows you to set the thickness value of the switch. By increasing the value, the border becomes thicker.

ToggleStateDisabled

The disabled state properties can be easily accessed under the ToggleStateDisabled category in the properties pane.
Here's a detailed description of the properties:

1. BackColor

This property allows you to get or set the background color of the toggle switch box. It's compatible with the use of RGB and HEX color values.

2. BackColorInner

This property allows you to get or set the background color of the switch.

3. BorderColor

This property allows you to get or set the toggle switch box border color.

4. BorderColorInner

This property allows you to set the border color of the switch.

5. BorderRadius

This property allows you to apply the radius value for the toggle switch box border edges. By increasing the value, the edges become more rounded.

6. BorderRadiusInner

This property allows you to apply the radius value for the switch edges. By increasing the value, the edges become more rounded.

7. BorderThickness

This property allows you to set a thickness value for the toggle switch box border. By increasing the value, the border becomes thicker.

8. BorderThicknessInner

This property allows you to set the thickness value of the switch. By increasing the value, the border becomes thicker.

We hope you will enjoy Bunifu Toggle Switch and that it will help you create better user experience for your users.
Should you have feedback or suggestions please send us via chat on the bottom right corner of the screen.
Last modified 1mo ago