c# winform self customized scrollbar makes desktop flicker
I use a textbox attach on a panel and then scroll the panel with my scrollbar instead of using windows default scroll bar.
But the problem is i use LockWindowUpdate when scrolling, which will affect the desktop window and make it flicker in windows xp.
The very interesting thing is once I open a file browser in winXp and scroll the scrollbar in the file browser. Then go back to my application and scroll my customized scrollbar again , the flicker disappear.
is there any know what really happen in this case. how does LockWindowUpdate work?
Thanks
protected override void OnScroll(ScrollEventArgs se)
{
if (se.Type == ScrollEventType.First)
{
LockWindowUpdate(this.Handle);
}
else if (se.Type == ScrollEventType.ThumbTrack /* || se.Type == ScrollEventType.ThumbPosition*/)
{
LockWindowUpdate(IntPtr.Zero);
this.Refresh();
LockWindowUpdate(this.Handle);
}
else
{
LockWindowUpdate(IntPtr.Zero);
this.Invalidate();
LockWindowUpdate(IntPtr.Zero);
}
base.OnScroll(se);
}
is the code for panel scroll event I just use my customized scroll bar to scroll the panel to right position.
if i use
SendMessage(parent.Handle, WM_SETREDRAW, false, 0);
SendMessage(parent.Handle, WM_SETREDRAW, true, 0);
the panel still jitter a lot .
And i found today , if i just focus a icon in desktop , the desktop will not flicker any more, but i add code in program by using
SetForegroundWindow(Win32API.GetDesktopWindow());
it 开发者_如何学Cdoesn't work also , So i am really tired of this issue.
is there anyone know this case?
try this:
protected override void OnPaintBackground(PaintEventArgs e)
{
// Left empty to avoid undesirable flickering.
}
This thread might be helpful: How do I suspend painting for a control and its children?
Try to use WM_SETREDRAW (disable) instead of LockWindowUpdate();
精彩评论