Al C
Al C

Reputation: 5377

Can I draw shapes in a StringGrid cell without calling OnDrawCell?

I know how to draw shapes during a StringGrid.OnDrawCell event (by calling methods of a TCanvas object). When I do so, however, my UI constantly flickers and consumes memory as the draw event fires over and over.

The lines causing the flickering say things like 'if [condition1 for a given cell=true] then [draw a red circle in the cell].' (I can post the actual code, if desired.)

So, is it possible a custom method can do the same thing--tell a grid to draw a circle in a cell if a statement resolves to true?

Upvotes: 2

Views: 1586

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596287

The actual act of drawing is not what causes flickering. Flickering occurs when the window is repeatedly refreshed over and over. That usually means you are not managing the window correctly, for instance if you were calling Refresh() instead of Invalidate() when your drawing conditions change. Setting the DoubleBuffer property to true is like putting a band-aid on it. It hides the issue but does not really address the root problem.

Upvotes: 5

Ken White
Ken White

Reputation: 125688

If you haven't already, set DoubleBuffered to true. This causes all of the drawing to be done on an off-screen bitmap, and then the entire bitmap is drawn at once. It usually eliminates the flickering.

As far as custom methods to do the cell drawing, OnDrawCell is the custom method. :)

Upvotes: 2

Related Questions