okay my second take on this GDI+ only method. There is something not right with using the picturebox as a drawing surface. Because if i substitute a panel for the picturebox, the dispose function calls without an exception. What i am seeing that is unwanted is a flicker when moved quickly. I have also set up a test painting onto a label control. this throws an exception if i try to dispose of the graphics in the paint handler. If i remove it, it functions normally without flicker.
I do not know if doing this creates a memory problem. if i perform the same dispose function in a label’s paint handler in Visual studio, I also get the same exception, so this must be a behaviour of the label control.
In VB i would solve flicker by setting the control double buffered property to true. This usually solves any redraw flicker. However i cant seem to set this in an MXS form and it appears that some controls like panel, even though they should inherit this class will still not allow you to set doublebuffered to true.
rollout dnpb "GDI+ paint" width:280 height:140
(
local acolor = dotnetclass "system.drawing.color"
local abrush = dotnetobject "System.Drawing.SolidBrush" acolor.yellow
local anotherbrush = dotnetobject "System.Drawing.SolidBrush" acolor.Fuchsia
local pos1x = 65
local pos1y = 65
local pos2x = 65
local pos2y = 65
dotnetcontrol pb "System.Windows.Forms.label" pos:[5,5] width:130 height:130
dotnetcontrol pb1 "System.Windows.Forms.panel" pos:[145,5] width:130 height:130
on pb paint e do
(
g = e.graphics
GDIsmoothing = dotnetclass "System.Drawing.Drawing2D.SmoothingMode"
g.SmoothingMode = GDIsmoothing.highspeed
g.FillRectangle abrush 3 3 124 124
g.FillEllipse anotherbrush (pos1x-15) (pos1y-15) 30 30
)
on pb1 paint e do
(
g = e.graphics
GDIsmoothing = dotnetclass "System.Drawing.Drawing2D.SmoothingMode"
g.SmoothingMode = GDIsmoothing.highspeed
g.FillRectangle abrush 3 3 124 124
g.FillEllipse anotherbrush (pos2x-15) (pos2y-15) 30 30
g.dispose()
)
on pb mouseMove sender arg do
(
if arg.button==arg.button.left then
(
pos1x = arg.x
pos1y = arg.y
pb.invalidate()
)
)
on pb1 mouseMove sender arg do
(
if arg.button==arg.button.left then
(
pos2x = arg.x
pos2y = arg.y
pb1.invalidate()
)
)
--
on dnpb close do
(
abrush.dispose()
anotherbrush.dispose()
)
)
createdialog dnpb
again, the more i experiment in max makes me think that for me, building a custom user control in VS is the best way to go…
