C# Analog Clock On Win Form

Language

Hi, Here is an C# Analogue Clock on windows form. .NET Framework 4.0

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted bypatcher (not verified)on Wed, 06/20/2018 - 01:26

A small patch: Less flicker and sharper graphics using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Analog_Clock_On_Form { public partial class ClockTime : UserControl { private const float PI = (float)Math.PI; private DateTime dTime; private float fRadius, fCenterX, fCenterY, fCenterCircleRadius, fHourLength; private float fMinLength, fSecLength, fHourThickness, fMinThickness, fSecThickness; private float fTicksThickness = 3; private Color secColor = Color.RoyalBlue; private Color circleColor = Color.Lime; public bool Draw1MinuteTicks { get; set; } = true; public bool Draw5MinuteTicks { get; set; } = true; public Color TicksColor { get; set; } = Color.Navy; public Color HourHandColor { get; set; } = Color.Orange; public Color MinuteHandColor { get; set; } = Color.Red; public Color SecondHandColor { get { return this.secColor; } set { this.secColor = value; this.circleColor = value; } } public ClockTime() { InitializeComponent(); this.DoubleBuffered = true; } private void ClockTime_Load(object sender, EventArgs e) { dTime = DateTime.Now; this.ClockTime_Resize(sender, e); } private void Timer1_Tick(object sender, EventArgs e) { this.dTime = DateTime.Now; this.Refresh(); } private void DrawLine(float fThickness, float fLength, Color color, float fRadians, PaintEventArgs e) { e.Graphics.DrawLine(new Pen(color, fThickness), fCenterX - (float)(fLength / 9 * Math.Sin(fRadians)), fCenterY + (float)(fLength / 9 * Math.Cos(fRadians)), fCenterX + (float)(fLength * Math.Sin(fRadians)), fCenterY - (float)(fLength * Math.Cos(fRadians))); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; } private void DrawPolygon(float fThickness, float fLength, Color color, float fRadians, PaintEventArgs e) { PointF A = new PointF((float)(fCenterX + fThickness * 2 * Math.Sin(fRadians + PI / 2)), (float)(fCenterY - fThickness * 2 * Math.Cos(fRadians + PI / 2))); PointF B = new PointF((float)(fCenterX + fThickness * 2 * Math.Sin(fRadians - PI / 2)), (float)(fCenterY - fThickness * 2 * Math.Cos(fRadians - PI / 2))); PointF C = new PointF((float)(fCenterX + fLength * Math.Sin(fRadians)), (float)(fCenterY - fLength * Math.Cos(fRadians))); PointF D = new PointF((float)(fCenterX - fThickness * 4 * Math.Sin(fRadians)), (float)(fCenterY + fThickness * 4 * Math.Cos(fRadians))); PointF[] points = { A, D, B, C }; e.Graphics.FillPolygon(new SolidBrush(color), points); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; } private void ClockTime_Paint(object sender, PaintEventArgs e) { float fRadHr = (dTime.Hour % 12 + dTime.Minute / 60F) * 30 * PI / 180; float fRadMin = (dTime.Minute) * 6 * PI / 180; float fRadSec = (dTime.Second) * 6 * PI / 180; DrawPolygon(this.fHourThickness, this.fHourLength, HourHandColor, fRadHr, e); DrawPolygon(this.fMinThickness, this.fMinLength, MinuteHandColor, fRadMin, e); DrawLine(this.fSecThickness, this.fSecLength, secColor, fRadSec, e); for (int i = 0; i

Add new comment