I am busy developing an C# win form application, that draws a graphical representation of a database structure in a hierarchical structure.
Everything is working fine, I just have a problem with scrolling. It has a bad flickering problem.
I have researched the following:
Call Invalidate()
when you want to refresh the surface (has helped a lot but still a little of a lag)
Also to set DoubleBuffered
property to True (Problem with this I get an ArgumentException
thrown with message "Parameter is not valid.". But I can set DoubleBuffered
to true on my main form)
Detail on my design
I have two class Node
and Link
they both have GraphicsPath
members, and they both have a public void Draw(Graphics g)
method to draw themselves.
I also have a user control call StructureMap
that has overridden the protected override void OnPaint(PaintEventArgs e)
method, to loop through every Node
calling it's draw function. The looping is simple because the Parent Node is link to the children nodes by a Link
object. All I have to do is call the parent node's draw method, and all its children nodes are also redrawn.
I am also preforming Hit testing the same way.
Is there maybe a better way? Why can't I have DoubleBuffered
set to true on my user control?
PS: This is my first post, let me know how I did?
Your flickering sound like it is caused by the amount of processing you have to do to draw the image.
One way to alleviate this is to draw your model to an offscreen bitmap, then your paint/scroll etc just draw that bitmap to the screen.
Then only update the bitmap if your model changes.