To prevent screen refresh and flickering in an application it is often useful to lock the screen. This can occur with data aware controls which involve iteration and can make the application look strange to the user. I have found 2 solutions to this problem, the first is the one I use most of the time, but the second also works well.
Solution 1
LockWindowUpdate(Handle);
try
// Code goes here
finally
LockWindowUpdate(0);
end;
Solution 2
SendMessage(Handle, WM_SETREDRAW, WPARAM(False), 0);
try
// Code goes here
finally
SendMessage(Handle, WM_SETREDRAW, WPARAM(True), 0);
RedrawWindow(Self.Handle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
end;
These 2 solutions help with screen refresh, however there are other instances when these do not work, for example when using a gradient background.
I also found when drawing to a canvas, for examples drawing to a TPaintBox.Canvas, if the drawing rountine is called from the OnPaint event, it is beneficial to set the DoubleBuffered property of the form to true, this improves the drawing and stops the drawing from flickering,
ReplyDelete