BELEN AnalogClock Code
BELEN AnalogClock Code
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 BELEN_AnalogClock
{
public partial class BELEN_AnalogClock : Form
{
Timer t = new Timer();
int WIDTH = 300, HEIGHT = 300, secHAND = 140, minHAND = 110, hrHAND = 80;
//center
int cx, cy;
Bitmap bmp;
Graphics g;
public BELEN_AnalogClock()
{
InitializeComponent();
}
//center
cx = WIDTH / 2;
cy = HEIGHT / 2;
//backcolor
this.BackColor = Color.White;
//timer
t.Interval = 1000; //in millisecond
t.Tick += new EventHandler(this.t_Tick);
t.Start();
}
//clear
g.Clear(Color.White);
//draw Circle
g.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, WIDTH, HEIGHT);
//draw figure
g.DrawString("12", new Font("Arial", 12), Brushes.Black, new PointF(140, 2));
g.DrawString("3", new Font("Arial", 12), Brushes.Black, new PointF(286,
140));
g.DrawString("6", new Font("Arial", 12), Brushes.Black, new PointF(142,
282));
g.DrawString("9", new Font("Arial", 12), Brushes.Black, new PointF(0, 140));
//second hand
handCoord = msCoord(ss, secHAND);
g.DrawLine(new Pen(Color.Red, 1f), new Point(cx,cy), new Point(handCoord[0],
handCoord[1]));
//minute hand
handCoord = msCoord(mm, minHAND);
g.DrawLine(new Pen(Color.Black, 2f), new Point(cx, cy), new
Point(handCoord[0], handCoord[1]));
//hour hand
handCoord = hrCoord(hh%12 , mm, hrHAND);
g.DrawLine(new Pen(Color.Gray, 3f), new Point(cx, cy), new
Point(handCoord[0], handCoord[1]));
//disp time
this.Text = "Analog Clock - " + hh + ":" + mm + ":" + ss;
//dispose
g.Dispose();
}
}
SAMPLE OUTPUT: