0

I'm working on a code editor using Windows Forms and I'm stepping into the typical "flickering" problem. However, it seems that traditional solutions do not work for me.

My application uses a large amount of Krypton Suite components, including the KryptonForm, which is inherited by every form from my project.

Whenever I call ShowDialog() on a new form, it flickers before being properly displayed. Even if it happens for a few milliseconds only, it's annoying. The "flickering" doesn't seem to come from the controls inside the form, because I only see a portion of Windows 11's title bar before the form "fixes itself" to its correct design.

In the GIF below, I try to display the "Find&Replace" form. You can see the attempt to display the Windows 11 title bar over Krypton's Form design:

enter image description here

The code that displays the second panel is this:

FindReplaceFormInput input = new FindReplaceFormInput();
input.Palette = KryptonCustomPaletteBase;
findReplaceForm.ShowDialog();

I am also sending a KryptonPalette, as in the FindReplaceForm's Load event, certain components will get their design from that global Palette:

private void FindReplaceForm_Load(object sender, EventArgs e)
{
    kryptonPanel1.Palette = Input.Palette;
    kryptonTextBox1.Palette = Input.Palette;
    // and so on...

    this.BringToFront();
    findTextBox.SelectAll();
}

Removing the content of Load() seems to show the classic Krypton design, but still with a small glimpse of the Win11 title bar before resolving itself.

I've also tried every other solution from Stack Overflow (and not only), including:

  • Set Form's DoubleBuffered Property to true
  • Set DoubleBuffered through the SetStyle method
  • Suspend the layout before showing the form or call Invalidate() and then Update()
  • Override WndProc

Is this a Krypton-related "bug"? Or is still Winforms-side?

2
  • There could be many reasons for this. Slow/heavy rendering. Creating many graphics object in-place while drawing instead of caching them. Implementing transparency (BackColor =TransparencyKey) to draw rounded Forms, or something else. You need to review the source code of this thing. Meanwhile, and as a workaround, p/invoke the AnimateWindow method this way to fade-in the form. The flickering part will be rendered in a low-opacity frames. Also, try another thing before that, remove the DoubleBuffered style. Commented May 28 at 23:38
  • That effect says that the default Theme is removed after the Form has been already created, and probably also sized (i.e., the custom Theme - if that's what it is - is applied after the OnLoad method is called, or in that context). Proceeding like this, there is way less stuff to consider and way less code to test in different scenarios, since the Desktop Window Manager and the .NET code have already done their part. Of course you have some drawbacks... Commented Jun 1 at 18:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.