Databound controls "flashing" as they are refreshed
It's a small thing but I was just wondering...
Visual Studio 2008, C#.
I have a master-detail form with databound controls. When user selects the record in a listbox, all the details are updated in multiple databound controls on the form.
As it happens, they kind of 'flash', or blink, when repopulated with new data and it's sort of like an electrical wave going across the form in a fraction of second :) don't know how to explain it better
Not a big deal, but still, it looks "shaky" and ugly, so, for the sake of ellegance, I was just wondering whether there is some easy way to prevent it?
I thought about calling SuspendLayout and ResumeLayout (on the container control), but what events should I handle? listBox_Sel开发者_JS百科ectedValueChanged for suspending it, I guess ... but for resuming?
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.
I didn't notice that "SuspendLayout" did anything for me, but worth giving it a shot. I think you would want to latch onto the "CurrentChanged" event for when the selected item is changed wholesale.
Have you set the DoubleBuffered (under "behavior" in the props window) to true?
control.DoubleBuffered = true;
- A bit 'o history: http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx
精彩评论