Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Lab_015_Clock_Animation
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- this.SetStyle(ControlStyles.UserPaint, true);
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Graphics objGraphics= e.Graphics;
- Rectangle objRectangle = new Rectangle(80, 20, 200, 200);
- LinearGradientBrush objLinearGradiantBrush = new LinearGradientBrush(objRectangle, Color.DarkGreen, Color.Blue, 90);
- objGraphics.FillEllipse(objLinearGradiantBrush, objRectangle);
- objLinearGradiantBrush.LinearColors = new Color[] { Color.DarkOrange, Color.Black };
- objGraphics.FillEllipse(objLinearGradiantBrush, 90, 30, 180, 180);
- SolidBrush objbrush = new SolidBrush(Color.White);
- Font objFont = new Font("Times new Roman", 12, FontStyle.Bold);
- objGraphics.DrawString("XII", objFont, objbrush, 170, 40);
- objGraphics.DrawString("XI", objFont, objbrush, 125, 50);
- objGraphics.DrawString("X", objFont, objbrush, 100, 80);
- objGraphics.DrawString("IX", objFont, objbrush, 100, 120);
- objGraphics.DrawString("VIII", objFont, objbrush, 110, 150);
- objGraphics.DrawString("VII", objFont, objbrush, 138, 175);
- objGraphics.DrawString("VI", objFont, objbrush, 170, 190);
- objGraphics.DrawString("V", objFont, objbrush, 210, 180);
- objGraphics.DrawString("IV", objFont, objbrush, 235, 150);
- objGraphics.DrawString("III", objFont, objbrush, 245, 120);
- objGraphics.DrawString("II", objFont, objbrush, 240, 80);
- objGraphics.DrawString("I", objFont, objbrush, 215, 50);
- objGraphics.TranslateTransform(120, 120);
- int hour = DateTime.Now.Hour;
- int min = DateTime.Now.Minute;
- int sec = DateTime.Now.Second;
- Pen hourPen = new Pen(Color.White, 2);
- Pen minPen = new Pen(Color.Yellow, 2);
- Pen secPen = new Pen(Color.Red, 1);
- double secondAngle = 2.0 * Math.PI * sec / 60.0;
- double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;
- double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;
- Point center = new Point(60, 7);
- Point hourHand = new Point((int)(10 * Math.Sin(hourAngle)),
- (int)(-10 * Math.Cos(hourAngle)));
- objGraphics.DrawLine(hourPen, center, hourHand);
- Point minHand = new Point((int)(15 * Math.Sin(minuteAngle)),
- (int)(-15 * Math.Cos(minuteAngle)));
- objGraphics.DrawLine(minPen, center, minHand);
- Point secHand = new Point((int)(5 * Math.Sin(secondAngle)),
- (int)(-5 * Math.Cos(secondAngle)));
- objGraphics.DrawLine(secPen, center, secHand);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Invalidate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement