How to change controls simultaneously without repainting each one?

Alexander picture Alexander · Mar 11, 2010 · Viewed 13.8k times · Source

For example I need to disable two buttons in runtime. After I disabled first button it bacame gray, the second - it also became gray. But I do not know how to make the repainting simultaneous!

I need something like that:

  1. freeze the Form (disable repainting)
  2. disable first button
  3. disable second button
  4. Enable Form repainting

How to implement that?

Answer

Remy Lebeau picture Remy Lebeau · Mar 11, 2010

Look at the Win32 API WM_SETREDRAW message. For example:

SendMessage(Handle, WM_SETREDRAW, False, 0);
Button1.Enabled := False;
Button2.Enabled := False;
SendMessage(Handle, WM_SETREDRAW, True, 0);
InvalidateRect(Handle, nil, True);