SHARE
TWEET

Untitled

a guest Jan 28th, 2020 180 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Lab_015_Clock_Animation
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.             this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  20.             this.SetStyle(ControlStyles.UserPaint, true);
  21.             this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  22.         }
  23.  
  24.         private void Form1_Paint(object sender, PaintEventArgs e)
  25.         {
  26.             Graphics objGraphics= e.Graphics;
  27.             Rectangle objRectangle = new Rectangle(80, 20, 200, 200);
  28.             LinearGradientBrush objLinearGradiantBrush = new LinearGradientBrush(objRectangle, Color.DarkGreen, Color.Blue, 90);
  29.             objGraphics.FillEllipse(objLinearGradiantBrush, objRectangle);
  30.             objLinearGradiantBrush.LinearColors = new Color[] { Color.DarkOrange, Color.Black };
  31.             objGraphics.FillEllipse(objLinearGradiantBrush, 90, 30, 180, 180);
  32.             SolidBrush objbrush = new SolidBrush(Color.White);
  33.             Font objFont = new Font("Times new Roman", 12, FontStyle.Bold);
  34.             objGraphics.DrawString("XII", objFont, objbrush, 170, 40);
  35.             objGraphics.DrawString("XI", objFont, objbrush, 125, 50);
  36.             objGraphics.DrawString("X", objFont, objbrush, 100, 80);
  37.             objGraphics.DrawString("IX", objFont, objbrush, 100, 120);
  38.             objGraphics.DrawString("VIII", objFont, objbrush, 110, 150);
  39.             objGraphics.DrawString("VII", objFont, objbrush, 138, 175);
  40.             objGraphics.DrawString("VI", objFont, objbrush, 170, 190);
  41.             objGraphics.DrawString("V", objFont, objbrush, 210, 180);
  42.             objGraphics.DrawString("IV", objFont, objbrush, 235, 150);
  43.             objGraphics.DrawString("III", objFont, objbrush, 245, 120);
  44.             objGraphics.DrawString("II", objFont, objbrush, 240, 80);
  45.             objGraphics.DrawString("I", objFont, objbrush, 215, 50);
  46.             objGraphics.TranslateTransform(120, 120);
  47.             int hour = DateTime.Now.Hour;
  48.             int min = DateTime.Now.Minute;
  49.             int sec = DateTime.Now.Second;
  50.             Pen hourPen = new Pen(Color.White, 2);
  51.             Pen minPen = new Pen(Color.Yellow, 2);
  52.             Pen secPen = new Pen(Color.Red, 1);
  53.             double secondAngle = 2.0 * Math.PI * sec / 60.0;
  54.             double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;
  55.             double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;
  56.             Point center = new Point(60, 7);
  57.             Point hourHand = new Point((int)(10 * Math.Sin(hourAngle)),
  58.                                         (int)(-10 * Math.Cos(hourAngle)));
  59.             objGraphics.DrawLine(hourPen, center, hourHand);
  60.  
  61.             Point minHand = new Point((int)(15 * Math.Sin(minuteAngle)),
  62.                                         (int)(-15 * Math.Cos(minuteAngle)));
  63.             objGraphics.DrawLine(minPen, center, minHand);
  64.  
  65.             Point secHand = new Point((int)(5 * Math.Sin(secondAngle)),
  66.                                         (int)(-5 * Math.Cos(secondAngle)));
  67.             objGraphics.DrawLine(secPen, center, secHand);
  68.         }
  69.  
  70.         private void timer1_Tick(object sender, EventArgs e)
  71.         {
  72.             Invalidate();
  73.         }
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top