Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- Application.EnableVisualStyles()
- type Azione =
- | Move
- type CircleIns() as this =
- inherit Control()
- let mutable r,cx,cy = 2,2,2
- let mutable pressed = false
- let mutable action = None
- let w2v = new Drawing2D.Matrix()
- let v2w = new Drawing2D.Matrix()
- let isClose (p : Point) (l : Point) =
- let dx = p.X - l.X
- let dy = p.Y - l.Y
- (dx * dx + dy * dy) < this.Raggio * this.Raggio
- let scrollTimer = new Timer(Interval=30)
- do
- scrollTimer.Tick.Add(fun _ ->
- match action with
- | Some a -> this.DoAction a
- | None ->()
- )
- member this.Raggio
- with get() = r
- and set(v) = r <- v
- member this.CentroX
- with get() = cx
- and set(v) = cx <- v
- member this.CentroY
- with get() = cy
- and set(v) = cy <- v
- override this.OnMouseDown e =
- let pc = new Point(this.CentroX,this.CentroY)
- let pmouse = new Point(e.X,e.Y)
- if (isClose pc pmouse) then
- if pressed then pressed <- false
- else
- pressed <- true
- action <- Some(Azione.Move)
- scrollTimer.Start()
- this.Invalidate()
- override this.OnMouseUp e =
- if pressed <> true then
- scrollTimer.Stop()
- this.Invalidate()
- override this.OnPaint e =
- let g = e.Graphics
- let d = this.Raggio*2
- if pressed then
- g.DrawEllipse(Pens.Green,this.CentroX-r,this.CentroY-r, d,d)
- g.FillEllipse(Brushes.Green,this.CentroX-r,this.CentroY-r, d,d)
- g.DrawRectangle(Pens.Blue,this.CentroX-r,this.CentroY-r,d,d)
- else
- g.DrawEllipse(Pens.Red,this.CentroX-r,this.CentroY-r, d,d)
- g.FillEllipse(Brushes.Red,this.CentroX-r,this.CentroY-r, d,d)
- g.DrawRectangle(Pens.Blue,this.CentroX-r,this.CentroY-r,d,d)
- g.DrawEllipse(Pens.Black,this.CentroX+d,this.CentroY+d,r/4,r/4)
- override this.OnResize e =
- this.Invalidate()
- member this.DoAction (act:Azione) =
- match act with
- | Azione.Move ->
- w2v.Translate(0.f, -10.f, Drawing2D.MatrixOrder.Append)
- v2w.Translate(0.f, -10.f)
- this.Invalidate()
- let f = new Form(Text="ciao", TopMost=true)
- f.Size <- new Size(500,500)
- let c = new CircleIns(Dock=DockStyle.Fill)
- c.Raggio <- 40
- c.CentroX <- 240
- c.CentroY <- 240
- f.Controls.Add(c)
- f.Show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement