Siticone Traffic Light
The SiticoneTrafficLight is a specialized WinForms control designed to simulate a realistic traffic signal.
It features smooth color transitions, built-in blinking logic, and a robust state management system.
Ideal for status indicators, process monitoring dashboards, and simulation interfaces.
State & Behavior
Control the active signal color and dynamic behaviors like blinking.
| Property | Type | Description & Usage Example |
|---|---|---|
State |
LightState |
light.State = LightState.Red;
The active color: Off, Red, Yellow, or Green.
Changing this triggers a smooth color transition animation.
|
IsBlinking |
bool | light.IsBlinking = true; When true, the light toggles between its current color and the Off color at the interval defined by BlinkInterval. |
BlinkInterval |
int | light.BlinkInterval = 500; The speed of the blinking effect in milliseconds. |
Appearance & Colors
Customize the colors used for each state and the transition speed.
| Property | Type | Description & Usage Example |
|---|---|---|
AnimationDuration |
int | light.AnimationDuration = 300; Time in milliseconds for the color to fade from one state to another. |
RedColor |
Color | light.RedColor = Color.Crimson; Color displayed when State is Red. |
YellowColor |
Color | light.YellowColor = Color.Gold; Color displayed when State is Yellow. |
GreenColor |
Color | light.GreenColor = Color.LimeGreen; Color displayed when State is Green. |
OffColor |
Color | light.OffColor = Color.DarkGray; Color displayed when State is Off or during the 'off' phase of a blink. |
BorderColor |
Color | light.BorderColor = Color.Gray; The color of the ring around the light. |
Events & Lifecycle
The control provides a rich event model, allowing you to intercept state changes or synchronize other UI elements with animations.
// 1. State Changing (Cancellable)
// Fires before the state updates. Allows validation logic.
trafficLight.StateChanging += (s, e) =>
{
// Prevent turning Green if the system is not ready
if (e.NextState == LightState.Green && !IsSystemReady())
{
e.Cancel = true;
MessageBox.Show("System check failed!");
}
};
// 2. State Changed
// Fires after the transition animation completes.
trafficLight.StateChanged += (s, e) =>
{
Console.WriteLine($"Light is now {e.NewState}");
};
// 3. Animation Events
trafficLight.AnimationStart += (s, e) => Console.WriteLine("Fading...");
trafficLight.AnimationEnd += (s, e) => Console.WriteLine("Fade Complete");
// 4. Click Interaction
trafficLight.LightClicked += (s, e) =>
{
Console.WriteLine($"Clicked while {e.StateOnClick}");
};
Designer Experience
Includes Visual Studio Smart Tags for quick configuration.
| Category | Features |
|---|---|
Behavior |
Quickly set State and toggle IsBlinking directly from the design surface. |
Actions |
Preview Animation Cycle: Runs a full Red -> Green -> Yellow -> Off animation loop in the designer. Toggle Blinking: Turns blinking on/off instantly for testing. |
Detailed Usage Examples
Example 1: Simple Status Indicator
Using the traffic light to show server connectivity status.
private void UpdateServerStatus(bool isConnected, bool hasWarnings)
{
if (!isConnected)
{
statusLight.State = LightState.Red;
statusLight.IsBlinking = true; // Blink red for error
}
else if (hasWarnings)
{
statusLight.State = LightState.Yellow;
statusLight.IsBlinking = false; // Solid yellow for warning
}
else
{
statusLight.State = LightState.Green;
statusLight.IsBlinking = false; // Solid green for OK
}
}
Example 2: Traffic Cycle Simulation
Simulates a standard traffic signal cycle using a Timer.
private Timer _trafficTimer;
private void StartTrafficCycle()
{
_trafficTimer = new Timer { Interval = 2000 };
_trafficTimer.Tick += (s, e) =>
{
switch (trafficLight1.State)
{
case LightState.Green:
trafficLight1.State = LightState.Yellow;
break;
case LightState.Yellow:
trafficLight1.State = LightState.Red;
break;
case LightState.Red:
default:
trafficLight1.State = LightState.Green;
break;
}
};
_trafficTimer.Start();
}