views:

104

answers:

2

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_SelectedValueChanged for suspending it, I guess ... but for resuming?

A: 

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;
Andrew Backer
OK I tried this - but doesn't seem to make a differenceThanks for the link though, I didn't know about it
Vibo
Darn. We moved to DevEx controls, so the flashing isn't an issue anymore except for multi-line text edits in specific circumstances.
Andrew Backer
+1  A: 

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.

Zach Johnson