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

Adding Bunifu Toggle Swtich at design time

Simply locate BunifuToggleSwitch control in your toolbox and drag it on to your form. You can then customize using custom properties as it will be elaborated later in this article

Adding Bunifu Toggle Switch at Runtime

We will use Form load event handler as shown below:

C# code

var bunifuToggleSwitch = new Bunifu.UI.Winforms.BunifuToggleSwitch();

this.Controls.Add(bunifuToggleSwitch);

VB.NET code

Dim bunifuToggleSwitch As New Bunifu.UI.Winforms.BunifuToggleSwitch

Controls.Add(bunifuToggleSwitch)

You can add code for listening to a change in the value selected (either true or false) by a user when using the event OnValuechange.

Here's an example where whenever a user toggles the switch ON, a message box pops-us with the message "Yes" and when switched OFF, a message box pops-us with the message "No":

[C#]

private void bunifuToggleSwitch1_OnValuechange(object sender, EventArgs e)
{
    if (bunifuToggleSwitch1.Value == true)
    {
        MessageBox.Show("Yes");
    }
    else
    {
        MessageBox.Show("No");
    }
}

[VB.NET]

Private Sub BunifuToggleSwitch1_OnValuechange(ByVal Sender As Object, ByVal e As EventArgs) Handles BunifuToggleSwitch1.OnValuechange

    If BunifuToggleSwitch1.Value = True Then
        MsgBox("Yes")
    Else
        MsgBox("No")
    End If

End Sub

Custom properties

  • Animation -This property makes a sliding and a bounce effect to the switch when switching states. It applies a numeric value that can set the animation speed.
  • Padding -It’s used to generate space around the switch, inside the toggle box borders. It receives a numeric value that will make the space around the switch.
  • Value - This property sets an on/off state to the toggle switch.

Toggle state ON and properties

  • ToggleStateOn - This particular state represents the On-state of the control. It is used to set a group of properties to the switch when the toggle’s state is on. These properties include:
  • BackColor - This property allows you to set the background color of the toggle switch box.
  • BackColorInner - This property allows you to set the background color of the switch.
  • BorderColor - This property allows you to set the toggle switch box border color.
  • BorderColorInner - This property allows you to set the border color of the switch
  • BorderRadius - This property allows you to apply the border radius to the toggle swtich
  • BorderRadiusInner - This property allows you to apply radius to the inner switch circle
  • BorderThickness - This property allows you to set the thickness of toggle switch border 
  • BorderThicknessInner - This property allows you to set border thickness of the toggle inner switch circle

Toggle state OFF and properties 

  • ToggleStateOff - This particular state represents the Off-state of the control. It is used to set a group of properties to the switch when the toggle’s state is off. These properties include:
  • BackColor - This property allows you to set the background color of the toggle switch box
  • BackColorInner - This property allows you to set the background color of the switch circle
  • BorderColor - This property allows you to set the toggle switch box border color
  • BorderColorInner - This property allows you to set the border color of the switch circle
  • BorderRadius - This property allows you to apply the toggle switch box a border radius
  • BorderRadiusInner - This property applies border radius to the switch circle
  • BorderThickness - This property applies border thickness to the toggle switch box 
  • BorderThicknessInner - This property applies border thickness to the switch circle

Toggle State Disabled and properties

  • ToggleStateDisabled - This particular state represents the disabled state of the control. It is used to set a group of properties to the switch when the toggle’s state is disabled. These properties are similar in nature to ToggleStateOn and ToggleStateOff.

They include:

  • BackColor - This property allows you to set the background color of the toggle switch box
  • BackColorInner - This property allows you to set the background color of the switch
  • BorderColor - This property allows you to set the toggle switch box border color
  • BorderColorInner - This property allows you to set the switch circle border color
  • BorderRadius - This property applies border radius to the toggle switch box 
  • BorderRadiusInner - This property applies border radius to the switch circle
  • BorderThickness - This property applies border thickness to the toggle switch box
  • BorderThicknessInner - This property applies border thickness to the inner switch circle

That's it!

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. 

Did this answer your question?