Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Hw7Clock/Hw7Clock.sln
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions Hw7Clock/Hw7Clock/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions Hw7Clock/Hw7Clock/Form1.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// часы
/// </summary>
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);
}
}
}
60 changes: 60 additions & 0 deletions Hw7Clock/Hw7Clock/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
24 changes: 24 additions & 0 deletions Hw7Clock/Hw7Clock/Hw7Clock.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions Hw7Clock/Hw7Clock/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ClockWinForms());
}
}
}
63 changes: 63 additions & 0 deletions Hw7Clock/Hw7Clock/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading