2017-03-24 30 views
-2

Windows窗体,创建多面板的(面板的包含多个面板的),每个小组的有不同的背景颜色,当运行应用程序,如果扩大形式手段,在Panles越来越摇动几毫秒,然后到达需要的地方。不能修复它。你能给我的想法来解决这个..闪烁的窗户形式

感谢

Saravanan

回答

0

固定it.Use这个代码,以避免震动,同时扩大窗户的形式。它正是所谓的闪烁。

使用的命名空间:

Using System.Runtime.InteropServices 

创建一个类,并编写代码:

internal static class NativeWinAPI 
{ 
    internal static readonly int GWL_EXSTYLE = -20; 
    internal static readonly int WS_EX_COMPOSITED = 0x02000000; 

    [DllImport("user32")] 
    internal static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

    [DllImport("user32")] 
    internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int  dwNewLong); 
}  

,并在窗体构造函数中添加代码:

public MyForm() 
{ 
    InitializeComponent(); 

    int style = NativeWinAPI.GetWindowLong(this.Handle,NativeWinAPI.GWL_EXSTYLE); 
    style |= NativeWinAPI.WS_EX_COMPOSITED; 
    NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style); 
} 

我得到这个结果来自: Avoid Flickering in Windows Forms?

所有感谢您的回复中
1

在窗体的resize事件,当你调整你的面板,在开始和Layout.Resume添加Layout.Suspend()( ) 最后。这应该停止摇晃。

晃动基本上是因为当窗体大小变化,以及子面板接收触发来调整自己,他们都制造恐慌和混乱之中自己在努力调整自己在给定的布局。当您暂停布局时,实际活动混乱不会显示在用户界面上,并且震动消失,但结果不是您可能想到的。但是,先试试然后再决定。

+0

首先,我为我的形式私人无效myform_Resize(对象发件人,EventArgs的){ this.SuspendLayout创建的事件(); this.ResumeLayout(); }但同样的震动再次发生..我做的方式是否正确? – User6667769

+0

以及我在运行时没有添加任何控件 – User6667769

+0

嗯......我想不是。如果它不在Form_Resize()中,你在调整面板的位置?你是否将它们停靠在窗体上? – athar13