๐น Kt-Switch
Overview
KtSwitch is a modern, customizable toggle switch control that provides an intuitive way to switch between on/off states for settings and features. With smooth animations, flexible styling options, and distinct visual states, it offers a sleek alternative to traditional checkboxes for binary choices in Windows Forms applications.
Key Properties
Checked
bool
false
Gets or sets whether the switch is in the ON position
Value
bool
false
Alternative property for checked state
Bg
KtColor
PRIMARY
Background color of the switch track
Thumb
KtColor
Empty
Color of the sliding thumb/circle
StateOn
KtSwitchState
-
Visual properties when switch is ON
StateOff
KtSwitchState
-
Visual properties when switch is OFF
Animation
int
5
Speed of the sliding animation
ThumbMargin
int
5
Padding/margin around the thumb circle
BorderRadius
int?
null
Corner radius of the switch track
BorderRadiusThumb
int?
null
Corner radius of the thumb circle
BorderThickness
int?
2
Thickness of the border
State Properties (KtSwitchState)
Each state object (StateOn/StateOff) has these properties:
Bg
KtColor
Background color of the switch track
Thumb
KtColor
Color of the sliding thumb
Border
KtColor
Border color of the switch
Events
CheckedChanged
CheckedChangedEventArgs
Fires when the switch state changes
OnValuechange
EventArgs
Alternative event for value changes
Basic Usage
Simple Switch
Switch with Label
Styling Examples
Custom Colors
Using State Properties
iOS-Style Switch
Material Design Style
Minimal Flat Style
Common Patterns
Settings Panel
Feature Toggles
Privacy Settings
Form with Multiple Switches
Advanced Features
Custom Animation Speed
Custom Thumb Margin
Programmatic Control
State-Based Styling
Layout Patterns
TableLayoutPanel Integration
GroupBox with Switches
Validation and State Management
Conditional Logic
Design Tips
Size Guidelines: Standard switch size is 60x30, but can be adjusted proportionally
Animation Speed: Use 3-8 for smooth animations; higher values are faster
Thumb Margin: Typically 3-5px for proper visual spacing
Color Contrast: Ensure ON and OFF states are clearly distinguishable
Border Radius: Set to half the height for pill-shaped switches
State Consistency: Use consistent colors across similar switches
Label Placement: Place labels to the left or right, maintaining alignment
Disabled State: The control automatically adjusts opacity when disabled
Accessibility Features
Automatic cursor change to hand pointer
Click anywhere on the switch to toggle
Smooth animation provides visual feedback
Clear visual distinction between ON/OFF states
Disabled state is visually apparent
Keyboard accessibility through standard focus/click patterns
Performance Notes
Animation uses a timer for smooth transitions
Thumb position calculated dynamically on resize
Graphics rendered using GDI+ for quality
Control automatically cleans up resources on disposal
Size Recommendations
Standard
60x30
5
Compact
50x25
3
Large
70x35
6
iOS Style
55x30
3
Material
50x25
2
Migration Notes
If migrating from CheckBox:
Best Practices
Use for Binary Choices: Switches work best for settings that take effect immediately
Provide Clear Labels: Always accompany switches with descriptive labels
Group Related Switches: Organize related toggles in panels or groups
Feedback on Change: Show confirmation or apply changes immediately
Disabled State: Use when options are unavailable but should remain visible
Consistent Positioning: Align switches vertically or use consistent spacing
State Persistence: Save switch states to user preferences
Visual Hierarchy: Use size and color to indicate importance
Last updated
Was this helpful?