i have a program like this
let form = new Form()
let drawArea = new Panel(Location = new Point(200,0), Height = 600, Width = 800)
let rectBrush = new SolidBrush(Color.Blue)
form.Controls.Add(drawArea)
drawArea.MouseClick.Add(fun args ->
drawArea.Paint.Add(fun e ->
e.Graphics.FillRectangle(rectBrush, args.X, args.Y, 50, 50)))
Application.Run(form)
so when i click a blue rectangle appears. However, where are these rectangles stored? is there any way to retrive a list of all the rectangles being part of the “drawArea”?
Otherwise, is there a way to add rectangles as child controllers to a panel or simular winform object?
Thank you
I don’t know of a way to retrieve these rectangles that way.
The best you can do is make a Rectangle class, and make it inherit from Control or UserControl. Then override it’s protected OnPaint(…) method. For example:
Now you can simple add an object of this type to the Controls collection like so:
With this approach you can easily create a collection of the rectangle objects and make them behave like you want them to.
Note that the examples I wrote above are in C#, but it shouldn’t be too difficult to port it to F#. Only reason I’m not doing it is because I’m not very familiar with its syntax. Your question is not F#-specific, but .NET-specific.
Also note that as it has been commented by Hans, the Paint event won’t fire until you call Invalidate().