Add project files.

This commit is contained in:
maxwes08
2025-11-04 12:12:17 +01:00
parent a3c4e90c79
commit f609553b8c
6 changed files with 316 additions and 0 deletions

83
Form1.cs Normal file
View File

@@ -0,0 +1,83 @@
namespace Traffic_Light
{
public partial class Form1 : Form
{
int state = 1;
bool reverse = false;
int borderSize = 10;
public Form1()
{
InitializeComponent();
}
public void Switch()
{
if (state == 3) reverse = true;
if (state == 1) reverse = false;
if (reverse)
{
state--;
}
else
{
state++;
}
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
var brush = new SolidBrush(Color.Black);
var pen = new Pen(Color.Black, borderSize);
g.DrawRectangle(pen,
50,
50,
50,
150
);
brush.Color = Color.Gray;
g.FillRectangle(brush,
50,
50,
50,
150
);
g.FillRectangle(brush, 50, 50, 50, 150);
if (state == 1)
{
brush.Color = Color.Green;
g.FillEllipse(brush, 50, 50, 50, 50);
return;
}
if (state == 2)
{
brush.Color = Color.Yellow;
g.FillEllipse(brush, 50, 100, 50, 50);
return;
}
if (state == 3)
{
brush.Color = Color.Red;
g.FillEllipse(brush, 50, 150, 50, 50);
return;
}
}
private void btn_switch_Click(object sender, EventArgs e)
{
Switch();
}
}
}