Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- type MyForm() as this =
- inherit Form()
- do
- this.SetStyle(ControlStyles.DoubleBuffer, true)
- this.SetStyle(ControlStyles.UserPaint, true)
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
- let f = new MyForm(Text="Clock", TopMost=true)
- f.Show()
- let cx, cy = 100, 100
- let drawTick (g:Graphics) (p:Pen) r l a =
- let a1 = (a / 180.) * System.Math.PI
- let x1 = int(r * cos(a1))
- let y1 = int(r * sin(a1))
- let x2 = int((r + l) * cos(a1))
- let y2 = int((r + l) * sin(a1))
- g.DrawLine(p, cx + x1, cy + y1, cx + x2, cy + y2)
- let drawLine (g:Graphics) p l a =
- drawTick g p 0. 10. (a + 180.)
- drawTick g p 0. l a
- let drawTime (g:Graphics) (t:System.DateTime) =
- let ah = float(t.Hour % 12) * 30. - 90.
- let am = float(t.Minute) * 6. - 90.
- let asec = float(t.Second) * 6. - 84.
- use hp = new Pen(Color.Black, Width=5.f)
- use mp = new Pen(Color.Black, Width=2.f)
- drawLine g hp 60. ah
- drawLine g mp 75. am
- drawLine g Pens.Red 75. asec
- let font = new Font("Times New Roman", 12.0f)
- f.Paint.Add(fun e ->
- let g = e.Graphics
- g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- g.FillEllipse(Brushes.Aquamarine, 0, 0, cx + 100, cy + 100)
- for a in 0. .. 6. .. 360. do
- drawTick g Pens.Black 95. 5. a
- for a in 0. .. 30. .. 360. do
- drawTick g Pens.Black 85. 15. a
- g.DrawEllipse(Pens.Black, 0, 0, cx + 100, cy + 100)
- g.FillEllipse(Brushes.Black, cx - 5, cy - 5, 10, 10)
- drawTime g (System.DateTime.Now)
- g.DrawString(System.DateTime.Now.ToString(), font, Brushes.Black, single(30), single(225))
- )
- let timer = new Timer(Interval=1000)
- timer.Tick.Add(fun _ ->
- f.Invalidate()
- )
- timer.Start()
- ////done by me
- //f.Paint.Add(fun e ->
- // let g1 = e.Graphics
- // g1.DrawEllipse(Pens.Black, 0, 0, cx + 100, cy + 100)
- // g1.FillEllipse(Brushes.Black, cx - 5, cy - 5, 10, 10)
- // g1.FillEllipse(Brushes.Blue, 0, 0, cx + 100, cy + 100 )
- // for a in 0. .. 6. .. 360. do
- // drawTick g1 Pens.Black 95. 5. a
- // g1.DrawLine(Pens.Black, cx - 15, cy, cx + 50, cy)
- // g1.DrawLine(Pens.Black, cx, cy + 15, cx, cy - 75)
- // f.Invalidate()
- //)
- //f.Paint.Add(fun e ->
- // let g2 = e.Graphics
- //
- //)
- //
- //f.Paint.Add(fun e ->
- // let g3 = e.Graphics
- //
- //)
- //
- //f.Paint.Add(fun e ->
- // let g4 = e.Graphics
- //
- //)
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement