I have a custom control in C#. I have noticed that calling Refresh
is much slower than I would like (about 0.1ms), even when I have an empty RePaint
function. Basically, my application processes a grid and, one by one, it refreshes each grid cell. This rather inefficient behavior is by design; when enabled I want to be able to actually see what each step of processing has done, and each step only ends up changing one cell. Toggling double-buffering does not make much difference.
Can anyone offer any advice?
Currently, the best improvement I've come up with is to replace my call to Refresh
with a call to Refresh2
. The latter function is an exact copy of Repaint
, except for two lines added to the top, Graphics g = Graphics.FromHwnd(this.Handle); g.Clear(BackColor);
and replacing e.Graphics
with g
. I am suspicious that there is some disadvantage to this, but it does cut the drawing speed in half. Take note that the control I am working with has no subcomponents, so things like validation don't have quite as much concern.