From f4e6c26cc8094ce5b2aa889f299b6a9f4d261b1a Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Wed, 12 May 2021 22:51:20 +0300 Subject: [PATCH 1/6] start code --- Hw7Clock/Hw7Clock.sln | 25 ++++++++ Hw7Clock/Hw7Clock/Form1.Designer.cs | 92 +++++++++++++++++++++++++++++ Hw7Clock/Hw7Clock/Form1.cs | 31 ++++++++++ Hw7Clock/Hw7Clock/Form1.resx | 60 +++++++++++++++++++ Hw7Clock/Hw7Clock/Hw7Clock.csproj | 9 +++ Hw7Clock/Hw7Clock/Program.cs | 23 ++++++++ 6 files changed, 240 insertions(+) create mode 100644 Hw7Clock/Hw7Clock.sln create mode 100644 Hw7Clock/Hw7Clock/Form1.Designer.cs create mode 100644 Hw7Clock/Hw7Clock/Form1.cs create mode 100644 Hw7Clock/Hw7Clock/Form1.resx create mode 100644 Hw7Clock/Hw7Clock/Hw7Clock.csproj create mode 100644 Hw7Clock/Hw7Clock/Program.cs diff --git a/Hw7Clock/Hw7Clock.sln b/Hw7Clock/Hw7Clock.sln new file mode 100644 index 0000000..c3a5fe0 --- /dev/null +++ b/Hw7Clock/Hw7Clock.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hw7Clock", "Hw7Clock\Hw7Clock.csproj", "{BE310794-D966-4366-BA56-E58D4B9C35EE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE310794-D966-4366-BA56-E58D4B9C35EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE310794-D966-4366-BA56-E58D4B9C35EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE310794-D966-4366-BA56-E58D4B9C35EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE310794-D966-4366-BA56-E58D4B9C35EE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7FEB7A03-9ACD-40E0-92FC-4202EDF15602} + EndGlobalSection +EndGlobal diff --git a/Hw7Clock/Hw7Clock/Form1.Designer.cs b/Hw7Clock/Hw7Clock/Form1.Designer.cs new file mode 100644 index 0000000..03f9123 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Form1.Designer.cs @@ -0,0 +1,92 @@ + +namespace Hw7Clock +{ + 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() + { + this.backgroundBox = new System.Windows.Forms.PictureBox(); + this.hourBox = new System.Windows.Forms.PictureBox(); + this.minuteBox = new System.Windows.Forms.PictureBox(); + this.secondBox = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.backgroundBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.hourBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.minuteBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.secondBox)).BeginInit(); + this.SuspendLayout(); + // + // backgroundBox + // + this.backgroundBox.Location = new System.Drawing.Point(54, 32); + this.backgroundBox.Name = "backgroundBox"; + this.backgroundBox.Size = new System.Drawing.Size(350, 350); + this.backgroundBox.TabIndex = 0; + this.backgroundBox.TabStop = false; + // + // hourBox + // + this.hourBox.Location = new System.Drawing.Point(74, 52); + this.hourBox.Name = "hourBox"; + this.hourBox.Size = new System.Drawing.Size(350, 350); + this.hourBox.TabIndex = 1; + this.hourBox.TabStop = false; + // + // minuteBox + // + this.minuteBox.Location = new System.Drawing.Point(111, 69); + this.minuteBox.Name = "minuteBox"; + this.minuteBox.Size = new System.Drawing.Size(350, 350); + this.minuteBox.TabIndex = 2; + this.minuteBox.TabStop = false; + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(935, 450); + this.Controls.Add(this.secondBox); + this.Controls.Add(this.minuteBox); + this.Controls.Add(this.hourBox); + this.Controls.Add(this.backgroundBox); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.backgroundBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.hourBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.minuteBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.secondBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox backgroundBox; + private System.Windows.Forms.PictureBox hourBox; + private System.Windows.Forms.PictureBox minuteBox; + private System.Windows.Forms.PictureBox secondBox; + } +} + diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs new file mode 100644 index 0000000..32d8129 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Hw7Clock +{ + public partial class Form1 : Form + { + Bitmap back, hour, minute, second; + + public Form1() + { + InitializeComponent(); + back = new Bitmap("..\\background.png"); + hour = new Bitmap("..\\hour.png"); + minute = new Bitmap("..\\minute.png"); + second = new Bitmap("..\\second.png"); + } + + private Bitmap Rotate(Bitmap rotater, float angle) + { + + } + } +} diff --git a/Hw7Clock/Hw7Clock/Form1.resx b/Hw7Clock/Hw7Clock/Form1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Hw7Clock/Hw7Clock/Form1.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Hw7Clock/Hw7Clock/Hw7Clock.csproj b/Hw7Clock/Hw7Clock/Hw7Clock.csproj new file mode 100644 index 0000000..a2d4310 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Hw7Clock.csproj @@ -0,0 +1,9 @@ + + + + WinExe + net5.0-windows + true + + + \ No newline at end of file diff --git a/Hw7Clock/Hw7Clock/Program.cs b/Hw7Clock/Hw7Clock/Program.cs new file mode 100644 index 0000000..1896aa2 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Hw7Clock +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} From 3abbbdebc4bf1c0bd26162c38dc8e47035f00456 Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Fri, 14 May 2021 23:02:29 +0300 Subject: [PATCH 2/6] clock write --- Hw7Clock/Hw7Clock/Form1.Designer.cs | 64 ++++------ Hw7Clock/Hw7Clock/Form1.cs | 89 ++++++++++++- Hw7Clock/Hw7Clock/Hw7Clock.csproj | 15 +++ .../Hw7Clock/Properties/Resources.Designer.cs | 63 +++++++++ Hw7Clock/Hw7Clock/Properties/Resources.resx | 120 ++++++++++++++++++ 5 files changed, 303 insertions(+), 48 deletions(-) create mode 100644 Hw7Clock/Hw7Clock/Properties/Resources.Designer.cs create mode 100644 Hw7Clock/Hw7Clock/Properties/Resources.resx diff --git a/Hw7Clock/Hw7Clock/Form1.Designer.cs b/Hw7Clock/Hw7Clock/Form1.Designer.cs index 03f9123..6cda96a 100644 --- a/Hw7Clock/Hw7Clock/Form1.Designer.cs +++ b/Hw7Clock/Hw7Clock/Form1.Designer.cs @@ -29,64 +29,46 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.backgroundBox = new System.Windows.Forms.PictureBox(); - this.hourBox = new System.Windows.Forms.PictureBox(); - this.minuteBox = new System.Windows.Forms.PictureBox(); - this.secondBox = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(this.backgroundBox)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.hourBox)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.minuteBox)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.secondBox)).BeginInit(); + this.components = new System.ComponentModel.Container(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // - // backgroundBox + // timer1 // - this.backgroundBox.Location = new System.Drawing.Point(54, 32); - this.backgroundBox.Name = "backgroundBox"; - this.backgroundBox.Size = new System.Drawing.Size(350, 350); - this.backgroundBox.TabIndex = 0; - this.backgroundBox.TabStop = false; + this.timer1.Enabled = true; + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // - // hourBox + // pictureBox1 // - this.hourBox.Location = new System.Drawing.Point(74, 52); - this.hourBox.Name = "hourBox"; - this.hourBox.Size = new System.Drawing.Size(350, 350); - this.hourBox.TabIndex = 1; - this.hourBox.TabStop = false; + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(282, 253); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; // - // minuteBox - // - this.minuteBox.Location = new System.Drawing.Point(111, 69); - this.minuteBox.Name = "minuteBox"; - this.minuteBox.Size = new System.Drawing.Size(350, 350); - this.minuteBox.TabIndex = 2; - this.minuteBox.TabStop = false; // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(935, 450); - this.Controls.Add(this.secondBox); - this.Controls.Add(this.minuteBox); - this.Controls.Add(this.hourBox); - this.Controls.Add(this.backgroundBox); + this.ClientSize = new System.Drawing.Size(282, 253); + this.Controls.Add(this.pictureBox1); + this.MinimumSize = new System.Drawing.Size(300, 300); this.Name = "Form1"; this.Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)(this.backgroundBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.hourBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.minuteBox)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.secondBox)).EndInit(); + this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.PictureBox backgroundBox; - private System.Windows.Forms.PictureBox hourBox; - private System.Windows.Forms.PictureBox minuteBox; - private System.Windows.Forms.PictureBox secondBox; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.PictureBox pictureBox1; } } diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs index 32d8129..d0881f6 100644 --- a/Hw7Clock/Hw7Clock/Form1.cs +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -12,20 +12,95 @@ namespace Hw7Clock { public partial class Form1 : Form { - Bitmap back, hour, minute, second; + Timer timer = new Timer(); + + private int coordX; + + private int coordY; + + private Bitmap img; + + private Graphics graphics; public Form1() { InitializeComponent(); - back = new Bitmap("..\\background.png"); - hour = new Bitmap("..\\hour.png"); - minute = new Bitmap("..\\minute.png"); - second = new Bitmap("..\\second.png"); } - private Bitmap Rotate(Bitmap rotater, float angle) + public void Form1_Load(object sender, EventArgs e) + { + img = new Bitmap(Width + 1, Height + 1); + coordX = Width / 2; + coordY = Height / 2; + this.BackColor = Color.Azure; + timer.Interval = 1000; + timer.Tick += new EventHandler(this.timer1_Tick); + timer.Start(); + } + + private void timer1_Tick(object sender, EventArgs e) + { + graphics = Graphics.FromImage(img); + int ss = DateTime.Now.Second; + int mm = DateTime.Now.Minute; + int hh = DateTime.Now.Hour; + int[] coord = new int[2]; + graphics.Clear(Color.Azure); + graphics.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, 300, 300); + graphics.DrawString("1", new Font("Elephant", 12), Brushes.Black, new PointF(210, 25)); + graphics.DrawString("2", new Font("Elephant", 12), Brushes.Black, new PointF(260, 70)); + graphics.DrawString("3", new Font("Elephant", 12), Brushes.Black, new PointF(280, 142)); + graphics.DrawString("4", new Font("Elephant", 12), Brushes.Black, new PointF(260, 200)); + graphics.DrawString("5", new Font("Elephant", 12), Brushes.Black, new PointF(210, 255)); + graphics.DrawString("6", new Font("Elephant", 12), Brushes.Black, new PointF(142, 276)); + graphics.DrawString("7", new Font("Elephant", 12), Brushes.Black, new PointF(70, 255)); + graphics.DrawString("8", new Font("Elephant", 12), Brushes.Black, new PointF(25, 200)); + graphics.DrawString("9", new Font("Elephant", 12), Brushes.Black, new PointF(0, 140)); + graphics.DrawString("10", new Font("Elephant", 12), Brushes.Black, new PointF(25, 70)); + graphics.DrawString("11", new Font("Elephant", 12), Brushes.Black, new PointF(70, 25)); + graphics.DrawString("12", new Font("Elephant", 12), Brushes.Black, new PointF(140, 2)); + coord = RotateMinSec(ss, 140); + graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + coord = RotateMinSec(mm, 110); + graphics.DrawLine(new Pen(Color.Black, 2f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + coord = RotateHour(hh % 12, mm,80); + graphics.DrawLine(new Pen(Color.Green, 3f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + pictureBox1.Image = img; + graphics.Dispose(); + } + + private int[] RotateMinSec(int value, int hLen) { + int[] coordinates = new int[2]; + value *= 6; + if (value >= 0 && value <= 180) + { + coordinates[0] = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); + coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + } + else + { + coordinates[0] = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); + coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + } + return coordinates; + } + private int[] RotateHour(int hValue, int mValue, int hLen) + { + int[] coordinates = new int[2]; + int value = (int)((hValue * 30) + (mValue * 0.5)); + if (value >= 0 && value <= 180) + { + coordinates[0] = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); + coordinates[1] = coordY + (int)(hLen * Math.Cos(Math.PI * value / 180)); + } + else + { + coordinates[0] = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); + coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + } + return coordinates; } } -} +} \ No newline at end of file diff --git a/Hw7Clock/Hw7Clock/Hw7Clock.csproj b/Hw7Clock/Hw7Clock/Hw7Clock.csproj index a2d4310..2faea65 100644 --- a/Hw7Clock/Hw7Clock/Hw7Clock.csproj +++ b/Hw7Clock/Hw7Clock/Hw7Clock.csproj @@ -6,4 +6,19 @@ true + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/Hw7Clock/Hw7Clock/Properties/Resources.Designer.cs b/Hw7Clock/Hw7Clock/Properties/Resources.Designer.cs new file mode 100644 index 0000000..596752a --- /dev/null +++ b/Hw7Clock/Hw7Clock/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Hw7Clock.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Hw7Clock.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Hw7Clock/Hw7Clock/Properties/Resources.resx b/Hw7Clock/Hw7Clock/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Properties/Resources.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 From 16f9f90c4c88ff1aea4c7aa44df8f9c5352704a4 Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Fri, 21 May 2021 18:59:59 +0300 Subject: [PATCH 3/6] fix bugs --- Hw7Clock/Hw7Clock/Form1.Designer.cs | 8 ++--- Hw7Clock/Hw7Clock/Form1.cs | 54 +++++++++++++---------------- Hw7Clock/Hw7Clock/Program.cs | 2 +- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/Hw7Clock/Hw7Clock/Form1.Designer.cs b/Hw7Clock/Hw7Clock/Form1.Designer.cs index 6cda96a..1ead9df 100644 --- a/Hw7Clock/Hw7Clock/Form1.Designer.cs +++ b/Hw7Clock/Hw7Clock/Form1.Designer.cs @@ -1,7 +1,7 @@  namespace Hw7Clock { - partial class Form1 + partial class ClockWinForms { /// /// Required designer variable. @@ -51,15 +51,15 @@ private void InitializeComponent() this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // - // Form1 + // ClockWinForms // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(282, 253); this.Controls.Add(this.pictureBox1); this.MinimumSize = new System.Drawing.Size(300, 300); - this.Name = "Form1"; - this.Text = "Form1"; + this.Name = "ClockWinForms"; + this.Text = "Clock"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs index d0881f6..fd148c7 100644 --- a/Hw7Clock/Hw7Clock/Form1.cs +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -10,9 +10,9 @@ namespace Hw7Clock { - public partial class Form1 : Form + public partial class ClockWinForms : Form { - Timer timer = new Timer(); + private Timer timer = new(); private int coordX; @@ -22,13 +22,13 @@ public partial class Form1 : Form private Graphics graphics; - public Form1() - { - InitializeComponent(); - } + public ClockWinForms() + => InitializeComponent(); public void Form1_Load(object sender, EventArgs e) { + Width = 300; + Height = 300; img = new Bitmap(Width + 1, Height + 1); coordX = Width / 2; coordY = Height / 2; @@ -44,7 +44,7 @@ private void timer1_Tick(object sender, EventArgs e) int ss = DateTime.Now.Second; int mm = DateTime.Now.Minute; int hh = DateTime.Now.Hour; - int[] coord = new int[2]; + (int, int) coord; graphics.Clear(Color.Azure); graphics.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, 300, 300); graphics.DrawString("1", new Font("Elephant", 12), Brushes.Black, new PointF(210, 25)); @@ -60,47 +60,41 @@ private void timer1_Tick(object sender, EventArgs e) graphics.DrawString("11", new Font("Elephant", 12), Brushes.Black, new PointF(70, 25)); graphics.DrawString("12", new Font("Elephant", 12), Brushes.Black, new PointF(140, 2)); coord = RotateMinSec(ss, 140); - graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); coord = RotateMinSec(mm, 110); - graphics.DrawLine(new Pen(Color.Black, 2f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + graphics.DrawLine(new Pen(Color.Black, 2f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); coord = RotateHour(hh % 12, mm,80); - graphics.DrawLine(new Pen(Color.Green, 3f), new Point(coordX, coordY), new Point(coord[0], coord[1])); + graphics.DrawLine(new Pen(Color.Green, 3f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); pictureBox1.Image = img; graphics.Dispose(); } - private int[] RotateMinSec(int value, int hLen) + private (int, int) GetCoordinates(int value, int hLen) { - int[] coordinates = new int[2]; - value *= 6; + (int, int) coordinates; if (value >= 0 && value <= 180) { - coordinates[0] = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); - coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + coordinates.Item1 = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); + coordinates.Item2 = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); } else { - coordinates[0] = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); - coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + coordinates.Item1 = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); + coordinates.Item2 = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); } return coordinates; } - private int[] RotateHour(int hValue, int mValue, int hLen) + private (int, int) RotateMinSec(int value, int hLen) + { + value *= 6; + return GetCoordinates(value, hLen); + } + + private (int, int) RotateHour(int hValue, int mValue, int hLen) { - int[] coordinates = new int[2]; int value = (int)((hValue * 30) + (mValue * 0.5)); - if (value >= 0 && value <= 180) - { - coordinates[0] = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); - coordinates[1] = coordY + (int)(hLen * Math.Cos(Math.PI * value / 180)); - } - else - { - coordinates[0] = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); - coordinates[1] = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); - } - return coordinates; + return GetCoordinates(value, hLen); } } } \ No newline at end of file diff --git a/Hw7Clock/Hw7Clock/Program.cs b/Hw7Clock/Hw7Clock/Program.cs index 1896aa2..28a4cf1 100644 --- a/Hw7Clock/Hw7Clock/Program.cs +++ b/Hw7Clock/Hw7Clock/Program.cs @@ -17,7 +17,7 @@ static void Main() Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new ClockWinForms()); } } } From fa66e5d14bef5fc5bf7f42ecf90400cddb6cf14e Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Thu, 3 Jun 2021 20:34:38 +0300 Subject: [PATCH 4/6] fix code --- Hw7Clock/Hw7Clock/Form1.Designer.cs | 5 ++-- Hw7Clock/Hw7Clock/Form1.cs | 44 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Hw7Clock/Hw7Clock/Form1.Designer.cs b/Hw7Clock/Hw7Clock/Form1.Designer.cs index 1ead9df..8065ba0 100644 --- a/Hw7Clock/Hw7Clock/Form1.Designer.cs +++ b/Hw7Clock/Hw7Clock/Form1.Designer.cs @@ -46,7 +46,7 @@ private void InitializeComponent() this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(282, 253); + this.pictureBox1.Size = new System.Drawing.Size(440, 314); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; @@ -55,7 +55,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(282, 253); + this.ClientSize = new System.Drawing.Size(440, 314); this.Controls.Add(this.pictureBox1); this.MinimumSize = new System.Drawing.Size(300, 300); this.Name = "ClockWinForms"; @@ -71,4 +71,3 @@ private void InitializeComponent() private System.Windows.Forms.PictureBox pictureBox1; } } - diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs index fd148c7..82f9b50 100644 --- a/Hw7Clock/Hw7Clock/Form1.cs +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -10,6 +10,9 @@ namespace Hw7Clock { + /// + /// часы + /// public partial class ClockWinForms : Form { private Timer timer = new(); @@ -38,49 +41,48 @@ public void Form1_Load(object sender, EventArgs e) timer.Start(); } + private void DrawNumber(string font, (int x, int y)[] coordinates) + { + var coordinatesNumbers = new (int, int)[] { (210, 25), (260, 70), (280, 142), (260, 200), (210, 255), (142, 276), (70, 255), (25, 200), (0, 140), (25, 70), (70, 25), (142, 2) }; + for (int i = 1; i < 13; ++i) + { + graphics.DrawString(i.ToString(), new Font(font, 12), Brushes.Black, new PointF(coordinates[i - 1].x, coordinates[i - 1].y)); + } + } + private void timer1_Tick(object sender, EventArgs e) { graphics = Graphics.FromImage(img); int ss = DateTime.Now.Second; int mm = DateTime.Now.Minute; int hh = DateTime.Now.Hour; - (int, int) coord; + (int x, int y) coord; graphics.Clear(Color.Azure); graphics.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, 300, 300); - graphics.DrawString("1", new Font("Elephant", 12), Brushes.Black, new PointF(210, 25)); - graphics.DrawString("2", new Font("Elephant", 12), Brushes.Black, new PointF(260, 70)); - graphics.DrawString("3", new Font("Elephant", 12), Brushes.Black, new PointF(280, 142)); - graphics.DrawString("4", new Font("Elephant", 12), Brushes.Black, new PointF(260, 200)); - graphics.DrawString("5", new Font("Elephant", 12), Brushes.Black, new PointF(210, 255)); - graphics.DrawString("6", new Font("Elephant", 12), Brushes.Black, new PointF(142, 276)); - graphics.DrawString("7", new Font("Elephant", 12), Brushes.Black, new PointF(70, 255)); - graphics.DrawString("8", new Font("Elephant", 12), Brushes.Black, new PointF(25, 200)); - graphics.DrawString("9", new Font("Elephant", 12), Brushes.Black, new PointF(0, 140)); - graphics.DrawString("10", new Font("Elephant", 12), Brushes.Black, new PointF(25, 70)); - graphics.DrawString("11", new Font("Elephant", 12), Brushes.Black, new PointF(70, 25)); - graphics.DrawString("12", new Font("Elephant", 12), Brushes.Black, new PointF(140, 2)); + var coordinatesNumbers = new (int x, int y)[] { (210, 25), (260, 70), (280, 142), (260, 200), (210, 255), (142, 276), (70, 255), (25, 200), (0, 140), (25, 70), (70, 25), (142, 2) }; + DrawNumber("Elephant", coordinatesNumbers); coord = RotateMinSec(ss, 140); - graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); + graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord.x, coord.y)); coord = RotateMinSec(mm, 110); - graphics.DrawLine(new Pen(Color.Black, 2f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); + graphics.DrawLine(new Pen(Color.Black, 2f), new Point(coordX, coordY), new Point(coord.x, coord.y)); coord = RotateHour(hh % 12, mm,80); - graphics.DrawLine(new Pen(Color.Green, 3f), new Point(coordX, coordY), new Point(coord.Item1, coord.Item2)); + graphics.DrawLine(new Pen(Color.Green, 3f), new Point(coordX, coordY), new Point(coord.x, coord.y)); pictureBox1.Image = img; graphics.Dispose(); } private (int, int) GetCoordinates(int value, int hLen) { - (int, int) coordinates; + (int x, int y) coordinates; if (value >= 0 && value <= 180) { - coordinates.Item1 = coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); - coordinates.Item2 = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + coordinates.x= coordX + (int)(hLen * Math.Sin(Math.PI * value / 180)); + coordinates.y = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); } else { - coordinates.Item1 = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); - coordinates.Item2 = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + coordinates.x = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); + coordinates.y = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); } return coordinates; } From 2448130ada460ecbd464759582f231542809d810 Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Thu, 3 Jun 2021 20:56:18 +0300 Subject: [PATCH 5/6] fix code --- Hw7Clock/Hw7Clock/Form1.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs index 82f9b50..6c1e41e 100644 --- a/Hw7Clock/Hw7Clock/Form1.cs +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -43,7 +43,6 @@ public void Form1_Load(object sender, EventArgs e) private void DrawNumber(string font, (int x, int y)[] coordinates) { - var coordinatesNumbers = new (int, int)[] { (210, 25), (260, 70), (280, 142), (260, 200), (210, 255), (142, 276), (70, 255), (25, 200), (0, 140), (25, 70), (70, 25), (142, 2) }; for (int i = 1; i < 13; ++i) { graphics.DrawString(i.ToString(), new Font(font, 12), Brushes.Black, new PointF(coordinates[i - 1].x, coordinates[i - 1].y)); @@ -59,7 +58,21 @@ private void timer1_Tick(object sender, EventArgs e) (int x, int y) coord; graphics.Clear(Color.Azure); graphics.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, 300, 300); - var coordinatesNumbers = new (int x, int y)[] { (210, 25), (260, 70), (280, 142), (260, 200), (210, 255), (142, 276), (70, 255), (25, 200), (0, 140), (25, 70), (70, 25), (142, 2) }; + var coordinatesNumbers = new (int x, int y)[] + { + (210, 25), + (260, 70), + (280, 142), + (260, 200), + (210, 255), + (142, 276), + (70, 255), + (25, 200), + (0, 140), + (25, 70), + (70, 25), + (142, 2) + }; DrawNumber("Elephant", coordinatesNumbers); coord = RotateMinSec(ss, 140); graphics.DrawLine(new Pen(Color.Red, 1f), new Point(coordX, coordY), new Point(coord.x, coord.y)); From 9016ba75931d0f2463fcc81ffea3b33f4a4e8892 Mon Sep 17 00:00:00 2001 From: MikePuzanov <89803250877@mail.ru> Date: Thu, 3 Jun 2021 20:57:09 +0300 Subject: [PATCH 6/6] fix --- Hw7Clock/Hw7Clock/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs index 6c1e41e..1169dc1 100644 --- a/Hw7Clock/Hw7Clock/Form1.cs +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -112,4 +112,4 @@ private void timer1_Tick(object sender, EventArgs e) return GetCoordinates(value, hLen); } } -} \ No newline at end of file +}