Bunifu Toggle Switch (variant)
Rapidly generate stylish toggle switches with the new variant

Overview

Bunifu Toggle Switch variant is a newly calibrated toggle switch with considerably great features in its design that the default Bunifu Toggle control may be unable to render.

Getting Started

This section describes adding Bunifu Toggle Switch (variant) at the designer level and during a runtime event.

Getting started with design view

Bunifu Toggle Switch is added to a Form by simply locating BunifuToggleSwitch2 in your Visual Studio toolbox, and dragging it to the form as demonstrated below. You can quickly customize the control using its properties in the smart tag. Later in this documentation, we will get into deeper detail about its features.

Adding the toggle switch at Run-time

To add Bunifu Toggle Switch at runtime, we will use the Form's load event to instantiate BunifuToggleSwitch2 and add it to the form as shown in the codes below:
C#
VB.NET
1
private void Form1_Load(object sender, EventArgs e)
2
{
3
//instatiate the toggle using Bunifu.UI.WinForms
4
BunifuToggleSwitch2 bunifuToggle = new BunifuToggleSwitch2();
5
//set the location of the toggle switch
6
bunifuToggle.Location = new Point(294, 160);
7
//set the toggle switch on an on-state
8
bunifuToggle.Checked = true;
9
//set the checked switch style to outline
10
bunifuToggle.CheckedSwitchStyle = BunifuToggleSwitch2.SwitchStyles.Outline;
11
//add the control to the form
12
this.Controls.Add(bunifuToggle);
13
}
Copied!
1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
2
'instatiate the toggle using Bunifu.UI.WinForms
3
Dim bunifuToggle As New BunifuToggleSwitch2()
4
'set the location of the toggle switch
5
bunifuToggle.Location = New Point(294, 160)
6
'set the toggle switch on an on-state
7
bunifuToggle.Checked = True
8
'set the checked switch style to outline
9
bunifuToggle.CheckedSwitchStyle = BunifuToggleSwitch2.SwitchStyles.Outline
10
'add the control to the form
11
Me.Controls.Add(bunifuToggle)
12
End Sub
13
Copied!
Let's deep dive and get insights into the available properties on the variant Bunifu Toggle Switch.

Properties

1. Checked

This property determines the toggle state of the control. When the property is set to true, it sets the toggle switch in an On state. By default the toggle switch is set on an Off state.
The CheckedChanged event fires whenever the toggle state changes. Here's a code snippet that changes the label text whenever the state changes.
C#
VB.NET
1
private void bunifuToggleSwitch_CheckedChanged(object sender, EventArgs e)
2
{
3
if (bunifuToggleSwitch.Checked)
4
{
5
bunifuLabel.Text = "ON";
6
}
7
else{
8
bunifuLabel.Text = "OFF";
9
}
10
}
Copied!
1
Private Sub bunifuToggleSwitch_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
2
If bunifuToggleSwitch.Checked Then
3
bunifuLabel.Text = "ON"
4
Else
5
bunifuLabel.Text = "OFF"
6
End If
7
End Sub
8
Copied!

2. CheckedBackColor

This property allows you to get or set the switch's box background color when the switch is on an On State. It supports both RGB and HEX color values.

3. UncheckedBackColor

This property allows you to get or set the switch's box background color when the switch is in an Off State. It supports both RGB and HEX color values.

4. CheckedSwitchColor

This property allows you to get or set the fill color of the switch thumb when the switch is on an On State. It supports both RGB and HEX color values.

5. CheckedSwitchStyle

This property allows you to get or set the surface style (enumeration) for the switch thumb when the switch is in an On State. The enumeration defines the following values: Fill and Outline.

6. UncheckedSwitchColor

This property allows you to get or set the fill color of the switch thumb when the switch is on an Off State. It supports both RGB and HEX color values.

7. UncheckedSwitchStyle

This property allows you to get or set the surface style (enumeration) for the switch thumb when the switch is in an Off State. The enumeration defines the following values: Fill and Outline.

8. OutlineThickness

This property allows you to set a thickness value for the switch thumb when its style set to outline. By increasing the value, the outline border of the swtich thumb becomes thicker.

Take Away

You can now generate more elegant toggle switches, which we hope will improve the appearance and feel of your UI while also providing a better user experience.
Please contact us via chat in the bottom right corner of the screen if you have feedback or recommendations.
Last modified 1mo ago