我试图运行一个漫长的过程来检索数据,并在检索数据时以对话框形式显示加载程序屏幕(简单形式)。我遇到的问题是后台工作程序正在运行时,加载程序屏幕只是闪烁而没有在加载程序窗体中呈现标签。后台运行时,您只能看到灰色矩形,如下所示。
有人知道为什么加载程序表单没有显示标签以及为什么闪烁吗?
private void LoadInfo()
{
try
{
workingLoader = new WorkingLoader();
mainWorker = new BackgroundWorker();
mainWorker.DoWork += MainWorker_DoWork;
mainWorker.RunWorkerCompleted += MainWorker_RunWorkerCompleted;
mainWorker.RunWorkerAsync();
workingLoader.ShowDialog();
}
catch (Exception ex)
{
if (workingLoader != null)
{
workingLoader.Dispose();
}
}
}
答案 0 :(得分:-1)
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);
}
And your form constructor should look as follows:
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);
}
In the code above, you might change this.Handle to something like MyFlickeringPanel.Handle