1. 程式人生 > >winfrom載入自定義控制元件、視窗pannel後閃爍問題

winfrom載入自定義控制元件、視窗pannel後閃爍問題

我用一個panel當容器,裡面有好多控制元件,載入的時候一直閃爍。

借鑑網友的思路: 視窗初始化介面加入程式碼

this.DoubleBuffered = true;//設定本窗體 SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. SetStyle(ControlStyles.DoubleBuffer, true); // 雙緩衝 對我好像沒有用 第二個方法: 重新定義視窗繪製
protected override CreateParams CreateParams
{
    get
    {
        CreateParams paras = base.CreateParams;
        paras.ExStyle |= 0x02000000;
        return paras;
    }
}
還是沒有什麼明顯改善第三個方法:預設我把視窗所有控制元件全部隱藏,載入完成後顯示。

private void XXX_Load(object sender, EventArgs e) { foreach (Control c in this.Controls) c.Visible = false;

 this.Shown += XXX_Shown;

}

void XXX_Shown(object sender, EventArgs e) { foreach (Control c in this.Controls) c.Visible = true; }

以下是網路上可搜尋到視窗載入和關閉的次序

   當 Windows Form 應用程式啟動時,會以下列順序引發主要表單的啟動事件:        System.Windows.Forms.Control.HandleCreated        System.Windows.Forms.Control.BindingContextChanged        System.Windows.Forms.Form.Load        System.Windows.Forms.Control.VisibleChanged        System.Windows.Forms.Form.Activated        System.Windows.Forms.Form.Shown

    當應用程式關閉時,會以下列順序引發主要表單的關閉事件:                  System.Windows.Forms.Form.Closing        System.Windows.Forms.Form.FormClosing        System.Windows.Forms.Form.Closed        System.Windows.Forms.Form.FormClosed        System.Windows.Forms.Form.Deactivate