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..8065ba0 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Form1.Designer.cs @@ -0,0 +1,73 @@ + +namespace Hw7Clock +{ + partial class ClockWinForms + { + /// + /// 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.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(); + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // pictureBox1 + // + 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(440, 314); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // ClockWinForms + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(440, 314); + this.Controls.Add(this.pictureBox1); + this.MinimumSize = new System.Drawing.Size(300, 300); + this.Name = "ClockWinForms"; + this.Text = "Clock"; + this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.PictureBox pictureBox1; + } +} diff --git a/Hw7Clock/Hw7Clock/Form1.cs b/Hw7Clock/Hw7Clock/Form1.cs new file mode 100644 index 0000000..1169dc1 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Form1.cs @@ -0,0 +1,115 @@ +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 ClockWinForms : Form + { + private Timer timer = new(); + + private int coordX; + + private int coordY; + + private Bitmap img; + + private Graphics graphics; + + 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; + this.BackColor = Color.Azure; + timer.Interval = 1000; + timer.Tick += new EventHandler(this.timer1_Tick); + timer.Start(); + } + + private void DrawNumber(string font, (int x, int y)[] coordinates) + { + 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 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) + }; + DrawNumber("Elephant", coordinatesNumbers); + coord = RotateMinSec(ss, 140); + 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.x, coord.y)); + coord = RotateHour(hh % 12, mm,80); + 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 x, int y) coordinates; + if (value >= 0 && 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.x = coordX - (int)(hLen * -Math.Sin(Math.PI * value / 180)); + coordinates.y = coordY - (int)(hLen * Math.Cos(Math.PI * value / 180)); + } + return coordinates; + } + + 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 value = (int)((hValue * 30) + (mValue * 0.5)); + return GetCoordinates(value, hLen); + } + } +} 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..2faea65 --- /dev/null +++ b/Hw7Clock/Hw7Clock/Hw7Clock.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net5.0-windows + true + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/Hw7Clock/Hw7Clock/Program.cs b/Hw7Clock/Hw7Clock/Program.cs new file mode 100644 index 0000000..28a4cf1 --- /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 ClockWinForms()); + } + } +} 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