Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as F# by lol22 ( 7 years ago )
module Mouse1
open System.Windows.Forms
open System.Drawing
open System.Numerics
open System
open Program


let mutable op = 0
type MovingBox(r:Rectangle) as this =
    inherit UserControl()
    let mutable box = r
    let bgcolor = Color.Red

  



    member this.X
        with get () = box.X
        and set(v) = box <- Rectangle(v, box.Y, box.Width, box.Height)
    member this.Y
        with get () = box.X
        and set(v) = box <- Rectangle(box.X, v, box.Width, box.Height)
    member this.Location
        with get() = Point(box.X, box.Y)
        and set(v:Point) = box <- Rectangle (v.X, v.Y, box.Width, box.Height) 


   
 

    member this.Contains(x,y) = 
        box.Contains(x,y)
 
    member this.OnPaint(g:Graphics) = 
       // g.DrawEllipse(Pens.Red,new Rectangle(0, 0,125, 125))
        use b = new SolidBrush(bgcolor)
        g.FillEllipse(b,box)
        g.DrawEllipse(Pens.Black,box)

   

    
 
                         



type MouseTest() as this = 
    inherit UserControl()

    do
        this.SetStyle(ControlStyles.AllPaintingInWmPaint ||| ControlStyles.OptimizedDoubleBuffer,true)
        //this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true)
    
    let boxes = ResizeArray<MovingBox>()

    
    
    let mutable box = Rectangle(50,50,100,100)
    
    let mutable start = None
    let duration = new System.TimeSpan(0,0,0,0,50)

    let mutable alpha = 0.f


    let mutable inbox = false
    let mutable drag = None
    let mutable newbox = None
    let mutable select1 = None
    let mutable select2 = None
    let mutable fpos = None
    let mutable spos = None


    let mkrect (sx,sy) (ex,ey) =
       Rectangle(min sx ex, min sy ey,125, 125)

   
    override this.OnPaint e=
        let g = e.Graphics
        //let a = int (alpha * 255.f)
        boxes |> Seq.iter (fun b ->
         b.OnPaint(g)
        )
        match newbox with
        | Some((sx,sy),(ex,ey)) ->
          let r = mkrect(sx,sy) (ex,ey)
          use p = new Pen(Color.Gray)
          p.DashStyle <- Drawing2D.DashStyle.DashDotDot
          g.DrawEllipse(p,r)
         | _ -> ()
     

     override this.OnMouseDown e =
         //Pick correlation
         let b = boxes |> Seq.tryFind (fun box -> box.Contains(e.X, e.Y))
         match b with
         | Some box ->
           let dx, dy = e.X - box.X, e.Y - box.Y
           drag <- Some (box, dx, dy)
         | _ ->
           newbox <- Some ((e.X, e.Y), (e.X, e.Y))
     override this.OnMouseMove e =
        
        match newbox with
        | Some ((sx, sy), _) ->
          newbox <- Some((sx, sy), (e.X, e.Y))
          
          this.Invalidate()
        | _ -> ()
        match drag with
        | Some(box, dx, dy) ->
                box.Location <- Point(e.X - dx   ,  e.Y  - dy)
                this.Invalidate()
        | _ -> ()
      

     override this.OnMouseUp e =
         match newbox with
         | Some((sx, sy), (ex, ey)) ->
          
           let r = MovingBox(mkrect (sx, sy) (ex, ey))
           boxes.Add(r)
           newbox <- None
           this.Invalidate()
         | _ ->  drag <- None
        

let toolbar = new Panel(Dock=DockStyle.Top, Height= 50, BackColor=Color.AliceBlue)  

let selectnode = new Button(Text="Nodo", Top=0, Left=0, Size=Size(80,50), BackColor=Color.Aqua)
selectnode.Click.Add(fun _ -> op <- 1)

let selectarch = new Button(Text="Arco", Top=0, Left=100, Size=Size(80,50), BackColor=Color.Aqua)
selectarch.Click.Add(fun _ -> op <- 2)

let selectbin =  new Button(Text="Elimina", Top=0, Left=200, Size=Size(80,50), BackColor=Color.Aqua)
selectbin.Click.Add(fun _ -> op <- 3)  


toolbar.Controls.Add(selectnode)
toolbar.Controls.Add(selectarch)
toolbar.Controls.Add(selectbin)

//Form
let f= new Form(Text = "Test")

//MouseTest



let mc = new MouseTest(Dock=DockStyle.Fill)
f.Controls.Add(mc)
f.Controls.Add(toolbar)




System.Windows.Forms.Application.Run(f)

 

Revise this Paste

Your Name: Code Language: