预防控制重绘在调整大小的Windows窗体 [英] Prevent redrawing of controls on resize for Windows Forms

查看:251
本文介绍了预防控制重绘在调整大小的Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TableLayoutPanel持有控件的SplitterPanel内一个动态数字。用户可能要调整大小的面板,以适应这些控件,避免使用滚动条。这造成在容器调整大小的抖动以及在容器内的控制。有时父容器大小调整期间滞后显著背后的鼠标的移动(高达3秒的滞后)。

I have a TableLayoutPanel which holds a dynamic number of controls inside a SplitterPanel. A user may want to resize the panel to fit these Controls to avoid use of a scroll bar. This creates jitter on the container resize as well as the controls within the container. Sometimes the parent container lags significantly behind movement of the mouse during resize (up to a 3 second lag).

有什么办法来防止父容器大小调整过程中控制的重新划分,比如调整大小时隐藏所有的元素或mousedrag期间停止resize事件而发生的历史中,只有射击上onMouseUp事件?

Is there any way to prevent redrawing of Controls during a parent container resize, such as hiding all elements during resize or halting a resize event which occuring during a mousedrag, firing only on an onMouseUp event?

推荐答案

由于汉斯评论, SuspendLayout ResumeLayout 在这种情况下工作良好,暂停为容器控件的绘制一起:

As Hans commented, SuspendLayout and ResumeLayout work well in this situation, along with Suspending the drawing of the control for the container:

public static class Win32 {

  public const int WM_SETREDRAW = 0x0b;

  [DllImport("user32.dll")]
  public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

  public static void SuspendPainting(IntPtr hWnd) {
    SendMessage(hWnd, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
  }

  public static void ResumePainting(IntPtr hWnd) {
    SendMessage(hWnd, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
  }
}



再从你调整事件:

Then from you resize events:

private void Form1_ResizeBegin(object sender, EventArgs e) {
  tableLayoutPanel1.SuspendLayout();
}

private void Form1_ResizeEnd(object sender, EventArgs e) {
  Win32.SuspendPainting(tableLayoutPanel1.Handle);
  tableLayoutPanel1.ResumeLayout();
  Win32.ResumePainting(tableLayoutPanel1.Handle);
  this.Refresh();
}

这篇关于预防控制重绘在调整大小的Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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