Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- open System.Timers
- (* use è una keyword che fa chiamare all'uscita dal blocco la dispose
- che rilascia esplicitamente le risorse. *)
- type ThrobberApple() =
- inherit UserControl()
- let mutable rotation = 0
- let pens : Pen array = Array.zeroCreate 12
- override x.OnPaint e =
- let graphics = e.Graphics
- (* Programmazione MODALE, configuro l'ambiente e lo uso. *)
- graphics.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- let pensize = x.Width / 10
- let from = int (single (x.Width - 2 * pensize) * 0.28f)
- let len = (x.Width - 2 * pensize) / 2 - from
- graphics.TranslateTransform(single (x.Width / 2), single (x.Width / 2))
- graphics.RotateTransform(30.f * single rotation)
- for i in 1..12 do
- graphics.DrawLine(pens.[i-1], from, 0, from + len, 0)
- graphics.RotateTransform(30.f)
- done
- override x.OnLoad _ =
- let timer = new Timer(Interval = 70.0, Enabled = true)
- for i in 1..12 do
- pens.[i-1] <- new Pen(Color.FromArgb((i * 20) + 15, Color.Black), single(x.Width / 15))
- pens.[i-1].StartCap <- Drawing2D.LineCap.Round
- pens.[i-1].EndCap <- Drawing2D.LineCap.Round
- timer.AutoReset <- true
- timer.Elapsed.Add(fun _ ->
- rotation <- (rotation + 1) % 12
- x.Refresh()
- )
- let form = new Form(Text = "Titolo")
- let throbberApple = new ThrobberApple()
- (* Il componente si adatta alle dimensioni
- (in realtà per ora solo alla Width, è una buona idea mettere
- valore Width = valore Height). *)
- throbberApple.Height <- 100
- throbberApple.Width <- 100
- form.Controls.Add(throbberApple)
- form.Show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement