how to stop flickering in C# windowsforms form Application?

人走茶凉 提交于 2020-01-03 01:51:27

问题


I have main Panel and Auto Scroll=true, and all controls are placed on main panel. Functionality works fine but when I click on any control or scroll down or up so it start flickering for a second each time I click or Scroll,

I also set

 DoubleBuffered = true; 

but it is not working for me.

could any body please suggest me solution or new code which can help me I alrasy spent 2 days on this problem. thanks in advance.


回答1:


You can try to put this into your forms class:

private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;

protected override void WndProc (ref Message m)
{
    if ((m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)
        && (((int)m.WParam & 0xFFFF) == 5))
    {
        // Change SB_THUMBTRACK to SB_THUMBPOSITION
        m.WParam = (IntPtr)(((int)m.WParam & ~0xFFFF) | 4);
    }
    base.WndProc (ref m);
}

You could also add this to your forms class constructor:

SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);

Im using windows 8, and i dont get flicker from a panel with AutoScroll=true. but the above methods should solve the flicker.



来源:https://stackoverflow.com/questions/16009743/how-to-stop-flickering-in-c-sharp-windowsforms-form-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!