diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..a07eb76 --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,59 @@ +namespace Traffic_Light +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + btn_switch = new Button(); + SuspendLayout(); + // + // btn_switch + // + btn_switch.Location = new Point(347, 225); + btn_switch.Name = "btn_switch"; + btn_switch.Size = new Size(112, 34); + btn_switch.TabIndex = 0; + btn_switch.Text = "Switch"; + btn_switch.UseVisualStyleBackColor = true; + btn_switch.Click += btn_switch_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(btn_switch); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + } + + #endregion + + private Button btn_switch; + } +} diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..02d5968 --- /dev/null +++ b/Form1.cs @@ -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(); + } + } +} diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..6540081 --- /dev/null +++ b/Program.cs @@ -0,0 +1,17 @@ +namespace Traffic_Light +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/Traffic Light.csproj b/Traffic Light.csproj new file mode 100644 index 0000000..8d6ff91 --- /dev/null +++ b/Traffic Light.csproj @@ -0,0 +1,12 @@ + + + + WinExe + net8.0-windows + Traffic_Light + enable + true + enable + + + \ No newline at end of file diff --git a/Traffic Light.sln b/Traffic Light.sln new file mode 100644 index 0000000..f2241f2 --- /dev/null +++ b/Traffic Light.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36414.22 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Traffic Light", "Traffic Light.csproj", "{0D7308CC-23AE-4748-9BEB-C8B87ACF6F5D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0D7308CC-23AE-4748-9BEB-C8B87ACF6F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D7308CC-23AE-4748-9BEB-C8B87ACF6F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D7308CC-23AE-4748-9BEB-C8B87ACF6F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D7308CC-23AE-4748-9BEB-C8B87ACF6F5D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5819F717-F58A-420A-8AEF-52A0C1848FEC} + EndGlobalSection +EndGlobal