0

这是一件小事,但我只是想知道......

视觉工作室 2008,C#。

我有一个带有数据绑定控件的主从表单。当用户在列表框中选择记录时,所有详细信息都会在表单上的多个数据绑定控件中更新。

碰巧的是,当重新填充新数据时,它们有点“闪烁”或眨眼,有点像电波在几分之一秒内穿过表格:) 不知道如何更好地解释它

没什么大不了的,但它仍然看起来“摇摇欲坠”和丑陋,所以,为了优雅,我只是想知道是否有一些简单的方法可以防止它?

我想过调用SuspendLayoutResumeLayout(在容器控件上),但是我应该处理哪些事件?listBox_SelectedValueChanged用于暂停它,我猜......但用于恢复?

4

2 回答 2

2

You could prevent the flicker by suspending painting when the control's data is refreshed.

From this stackoverflow question:

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

private const int WM_SETREDRAW = 11; 

public static void SuspendDrawing(Control parent)
{
    SendMessage(parent.Handle, WM_SETREDRAW, false, 0);
}

public static void ResumeDrawing(Control parent)
{
    SendMessage(parent.Handle, WM_SETREDRAW, true, 0);
    parent.Refresh();
}

As far as which events to handle, I'm not sure.

于 2010-02-18T01:18:46.923 回答
0

我没有注意到“SuspendLayout”为我做了什么,但值得一试。我认为您希望在所选项目被批发更改时锁定“CurrentChanged”事件。

您是否将 DoubleBuffered(在道具窗口中的“行为”下)设置为 true?

control.DoubleBuffered = true;
于 2010-02-18T00:45:04.973 回答