4

我正在制作一个 Windows 窗体应用程序,主要是我的屏幕分为 3 个部分,例如

===========================================================================
                    Top panel (it doesn't flicker)
===========================================================================
||         || 'it has a panel & panel contains a table layout,this tabble layout'
||         || 'has a picture box and a label, picture & text of label is'           
||         ||'changed on the click of side bar menu' (PROB: this flickers a lot)
||side bar ||==============================================================
||(doesn't ||'this part also has a panel and panel contains different table'
||flicker) ||'layouts and on the click of a menu, related table layout is shown and'  
||         ||'some of the parts of table layout are created dynamically.'
||         ||           
||         ||                (PROB: this flickers a lot)
||         ||

我搜索了很多,到处都找到了这个解决方案,我尝试了这个

public constructor()
    {
        InitializeComponent();
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        this.DoubleBuffered = true;
        DoubleBuffered = true;
        SetStyle(ControlStyles.UserPaint |
                      ControlStyles.AllPaintingInWmPaint |
                      ControlStyles.ResizeRedraw |
                      ControlStyles.ContainerControl |
                      ControlStyles.OptimizedDoubleBuffer |
                      ControlStyles.SupportsTransparentBackColor
                      , true);
    }

我也试过这个

protected override CreateParams CreateParams
{
get
{
CreateParams handleParam = base.CreateParams;
handleParam.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED       
return handleParam;
}
}

它将我屏幕的整个背景更改为黑色。

但问题仍然存在,有人可以告诉我如何解决这个问题以及我在哪里做错了吗?提前非常感谢。

4

1 回答 1

2

如果没有更多内容,我的直觉是您要么在这些区域添加大量数据,要么正在进行大量调整大小。

在您更新屏幕(将行添加到列表视图/框/等)或调整屏幕大小或其他任何会导致屏幕重绘的地方尝试此操作。前任:

public void something_resize(object sender, EventArgs e)
{
    try
    {
        this.SuspendLayout(); 

        // Do your update, add data, redraw, w/e. 
        // Also add to ListViews and Boxes etc in Batches if you can, not item by item.  
    }
    catch
    {
    }
    finally
    {
        this.ResumeLayout(); 
    }
} 

将 ResumeLayout() 调用放在 finally 块中很重要,因为如果由于 w/e 原因发生异常,则无论您对异常做什么,您都希望您的窗口进行布局。

于 2013-05-08T19:50:40.693 回答