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 Clock/Clock/Clock.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 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clock", "Clock\Clock.csproj", "{F80D3B91-059D-4932-B6F9-68EDC93303DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F80D3B91-059D-4932-B6F9-68EDC93303DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F80D3B91-059D-4932-B6F9-68EDC93303DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F80D3B91-059D-4932-B6F9-68EDC93303DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F80D3B91-059D-4932-B6F9-68EDC93303DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B5180CCA-4140-42E2-9B3E-012D1D8F3759}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions Clock/Clock/Clock/Clock.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
70 changes: 70 additions & 0 deletions Clock/Clock/Clock/Form1.Designer.cs

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

80 changes: 80 additions & 0 deletions Clock/Clock/Clock/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Clock;
using System.Drawing.Drawing2D;

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void DrawClock(Graphics graph)
{
// The center of the clock will be in the center of the shape
PointF clockCenter = new(pictureBox1.Width / 2, pictureBox1.Height / 2);

// Multiply by 4/5 so that the clock does not go beyond the form, but at the same time occupies most of the form
var radius = Math.Min(pictureBox1.Width, pictureBox1.Height) * 4/5 * 1/2;

// Draw clock
graph.DrawEllipse(new(Brushes.Black, 5), pictureBox1.Width / 2 - radius, pictureBox1.Height / 2 - radius, radius * 2, radius * 2);

// If the counter is divided by 5, then draw a thick hour mark and a number
int fontSize = (int)Math.Floor((decimal)radius / 9);
Matrix matrix = new();

for (int i = 60; i > 0; i--)
{
// if the counter is divided by 5, then draw a thick hour mark and a number
if (i % 5 == 0)
{
graph.DrawString($"{i / 5}", new Font("Arial", fontSize), Brushes.Black, clockCenter.X - fontSize, clockCenter.Y - radius);
graph.DrawLine(new(Brushes.Black, 5), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius * 1.94 / 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius));
}
else
{
// Draw a minute mark
graph.DrawLine(new(Brushes.Black, 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius * 1.94 / 2), (int)Math.Floor(clockCenter.X), (int)Math.Floor(clockCenter.Y - radius));

}

// We change the angle by -6 (that is, we reduce the minute)
matrix.RotateAt(-6.0F, clockCenter);
graph.Transform = matrix;
}
}


private void DrawHand(Graphics graph, Color color, float angleRelativeStartingPoint, float length, float width)
{
PointF clockCenter = new(pictureBox1.Width / 2, pictureBox1.Height / 2);
var radius = Math.Min(pictureBox1.Width, pictureBox1.Height) * 4 / 5 * 1 / 2;
Matrix matrix = new();
matrix.RotateAt(angleRelativeStartingPoint, clockCenter);
graph.Transform = matrix;
graph.DrawLine(new(color, radius * width), clockCenter, new(clockCenter.X, radius * (1 - length)));
}

private void DrawAllHands(Graphics e)
{
// draw the second hand
DrawHand(e, Color.Red, DateTime.Now.Second * 6F, 0.6F, 0.01F);

// draw the minute hand
DrawHand(e, Color.Black, (DateTime.Now.Minute + DateTime.Now.Second / 60f) * 6F, 0.3F, 0.012F);

// draw the hour hand
DrawHand(e, Color.Black, (DateTime.Now.Hour + DateTime.Now.Minute / 60f + DateTime.Now.Second / 3600f) * 30F, 0.2F, 0.015F);
}

private void PictureBoxPaint(object sender, PaintEventArgs e)
{
DrawClock(e.Graphics);
DrawAllHands(e.Graphics);
}

private void TimerTick(object sender, EventArgs e)
{
pictureBox1.Invalidate();
}
}
82 changes: 82 additions & 0 deletions Clock/Clock/Clock/Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<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>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAcYAAAGHCAYAAAAqZvLgAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAS
cQAAEnEB89x6jgAAAshJREFUeF7twQENAAAAwqD3T20ONyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAftQA18UAAbbfLIIAAAAASUVORK5CYII=
</value>
</data>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
16 changes: 16 additions & 0 deletions Clock/Clock/Clock/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Clock;

internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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());
}
}