Advertisement
wandrake

Untitled

Feb 29th, 2012
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.79 KB | None | 0 0
  1. open System.Windows.Forms
  2. open System.Drawing
  3. open System.Timers
  4.  
  5. (*  use è una keyword che fa chiamare all'uscita dal blocco la dispose
  6.     che rilascia esplicitamente le risorse. *)
  7.  
  8. type ThrobberApple() =
  9.     inherit UserControl()
  10.    
  11.     let mutable rotation = 0
  12.     let pens : Pen array = Array.zeroCreate 12
  13.  
  14.     override x.OnPaint e =
  15.         let graphics = e.Graphics
  16.  
  17.         (*  Programmazione MODALE, configuro l'ambiente e lo uso. *)
  18.         graphics.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
  19.  
  20.         let pensize = x.Width / 10
  21.  
  22.         let from = int (single (x.Width - 2 * pensize) * 0.28f)
  23.         let len = (x.Width - 2 * pensize) / 2 - from
  24.  
  25.         graphics.TranslateTransform(single (x.Width / 2), single (x.Width / 2))
  26.  
  27.         graphics.RotateTransform(30.f * single rotation)
  28.  
  29.         for i in 1..12 do
  30.             graphics.DrawLine(pens.[i-1], from, 0, from + len, 0)
  31.             graphics.RotateTransform(30.f)
  32.         done
  33.  
  34.     override x.OnLoad _ =
  35.         let timer = new Timer(Interval = 70.0, Enabled = true)
  36.         for i in 1..12 do
  37.             pens.[i-1] <- new Pen(Color.FromArgb((i * 20) + 15, Color.Black), single(x.Width / 15))
  38.             pens.[i-1].StartCap <- Drawing2D.LineCap.Round
  39.             pens.[i-1].EndCap <- Drawing2D.LineCap.Round
  40.  
  41.         timer.AutoReset <- true
  42.         timer.Elapsed.Add(fun _ ->
  43.             rotation <- (rotation + 1) % 12
  44.             x.Refresh()
  45.         )
  46.  
  47.  
  48. let form = new Form(Text = "Titolo")
  49.  
  50. let throbberApple = new ThrobberApple()
  51.  
  52.  
  53. (*  Il componente si adatta alle dimensioni
  54.     (in realtà per ora solo alla Width, è una buona idea mettere
  55.     valore Width = valore Height). *)
  56.  
  57. throbberApple.Height <- 100
  58. throbberApple.Width <- 100
  59.  
  60. form.Controls.Add(throbberApple)
  61. form.Show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement