Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ulteriori informazioni su F# all'indirizzo http://fsharp.net
- open System.Windows.Forms
- open System.Drawing
- #load "ColorPicker.fsx"
- open ColorPicker
- type PaintSimple() as x=
- inherit UserControl()
- let mutable pressed = false
- let mutable _line: Point list = []
- // ClientSize -> dimensioni dell'area effettivamente disegnabile, al netto
- // dei bordi
- let mutable _buffer: Bitmap = null
- let _allocateBuffer() =
- _buffer <- new Bitmap(x.ClientSize.Width, x.ClientSize.Height)
- use graphics = Graphics.FromImage(_buffer)
- graphics.FillRectangle(Brushes.White, 0, 0, _buffer.Width, _buffer.Height)
- do
- //x.DoubleBuffered <- true
- x.SetStyle(ControlStyles.OptimizedDoubleBuffer, true)
- _allocateBuffer()
- member x.Buffer = _buffer
- member x.Undo() =
- _line <- []
- x.Invalidate()
- override x.OnPaintBackground evt = ()
- override x.OnClientSizeChanged evt =
- base.OnClientSizeChanged evt
- _allocateBuffer()
- x.Invalidate()
- override x.OnKeyUp evt =
- match evt.KeyCode with
- //| Keys.Z when evt.Control -> x.Undo()
- | Keys.Z -> x.Undo()
- override x.OnMouseDown evt =
- base.OnMouseDown evt
- if _line <> [] then
- use graphics = Graphics.FromImage(_buffer)
- graphics.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- if _line.Length > 1 then
- graphics.DrawLines(Pens.Black, (List.toArray _line))
- _line <- []
- pressed <- true
- override x.OnMouseUp evt =
- base.OnMouseUp evt
- //points <- (_color, _line)::points
- //_line <- []
- pressed <- false
- override x.OnMouseMove evt =
- base.OnMouseMove evt
- if pressed then
- //points <- evt.Location::points
- _line <- evt.Location::_line
- x.Invalidate()
- override x.OnPaint evt =
- let graphics = evt.Graphics
- graphics.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
- //if points.Length > 1 then
- graphics.DrawImage(_buffer, 0, 0)
- if _line.Length > 1 then
- graphics.DrawLines(Pens.Black, List.toArray _line)
- (*for list in points do
- match list with
- | (a, b) ->
- if b.Length > 1 then
- graphics.DrawLines(new Pen(a), List.toArray b)*)
- let form = new Form(Text="Paint bacato", TopMost=true)
- //let paint = new PaintSimple(Width=500, Height=450)
- let paint = new PaintSimple(Width=640,Height=480)
- //colorPicker.BorderStyle <- BorderStyle.FixedSingle
- paint.BorderStyle <- BorderStyle.FixedSingle
- //form.Controls.Add(paint)
- form.Controls.Add(paint)
- form.Show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement