如何禁用更新大量控件的屏幕更新? [英] How can I disable screen update which updating a lot of controls?

查看:138
本文介绍了如何禁用更新大量控件的屏幕更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含50个或更多控件的表单,我在运行时创建和添加。我不想看到一个一个出现;我宁愿在开始时禁用绘图/开始缓冲然后看到它们都出现在一起。



我似乎回想起在大约10年前在BCB这样的事情,但忘记了如何。

解决方案

我不知道是否有一个Delphi特定的方法来做到这一点,但是使用Win32 API,这是通过 WM_SETREDRAW 消息。



编辑:感谢Ken White和Sertac Akyuz下面的示例代码。

  begin 
//延迟更新
SendMessage(Handle,WM_SETREDRAW,WPARAM(False),0);
try
//在这里创建所有控件
finally
//确保重新启用更新
SendMessage(Handle,WM_SETREDRAW,WPARAM(True),0 );
//无效; //可能需要反映变化
end;
结束


I have a form with 50 or more controls which I create and add at runtime. I don't want to see then appear one by one; I would rather disable drawing/start buffering at the start & then see them all appear at once.

I seem to recall doing something like this in BCB about 10 years ago, but forget how.

解决方案

I'm not sure if there's a Delphi-specific method to do this, but using the Win32 API, this is done through the WM_SETREDRAW message.

Edit: Thanks to Ken White and Sertac Akyuz for the sample code below.

begin
  // Defer updates
  SendMessage(Handle, WM_SETREDRAW, WPARAM(False), 0);
  try
    // Create all your controls here
  finally
    // Make sure updates are re-enabled
    SendMessage(Handle, WM_SETREDRAW, WPARAM(True), 0);
    // Invalidate;  // Might be required to reflect the changes  
  end;
end;

这篇关于如何禁用更新大量控件的屏幕更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆