Мерцание загрузчика не рендеринг WinForm - PullRequest
0 голосов
/ 25 апреля 2019

Я пытаюсь запустить длинный процесс для извлечения данных и отображения экрана загрузчика (простая форма) в виде диалога во время извлечения данных. Проблема, с которой я сталкиваюсь, заключается в том, что во время работы фонового работника экран загрузчика просто мигает и не отображает метки в форме загрузчика. Вы можете видеть только серые прямоугольники, пока работает фон, как показано ниже.

enter image description here

Кто-нибудь знает, почему в форме загрузчика не отображаются их ярлыки и почему она мигает?

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();
        }
    }
}

1 Ответ

0 голосов
/ 25 апреля 2019

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...