سؤال

I have a WPF UserControl that displayed in a Winform as Element Host.

When I change the screen size quickly or resize it I see a black flashbacks in the background until the UserControl comes to the appropriate size.

I read about it in several places.

All the places I read them talk it happens only in the UserControl Load and bring solutions accordingly.

One question I've seen talking about it happening on Resize. But the solution offered there is as well to Load.

Black background on resizing elementhost

I tried on Resize of the screen to perform the following: UserControl.CreateGraphics (); , it does not leaves black lines like the above answer said.

I guess it's because I used it in Resize and not on Load.

Besides, I could not find anything.

If anyone encountered this and found a solution I would love to answer.

هل كانت مفيدة؟

المحلول 2

What helped me in the end it following lines of code (in Winform):

    protected override void OnResize(EventArgs e)
    {
        this.SuspendLayout();
        base.OnResize(e);
        this.ResumeLayout();
    }

نصائح أخرى

We usually face flickering issues while developing windows application with forms having many controls on it. A very neat way to get rid of this flickering is double buffering the whole form and its child controls. However, this would not speed up the control painting but it will hold the screen for a while and just show the updated screen instead of flickering. To implement this we need to enable the WS_EX_COMPOSITED flag. Just add the following code to your form's code.

C#:

protected override CreateParams CreateParams
{
   get 
    {
    CreateParams cp = base.CreateParams;
    cp.ExStyle |= 0x02000000; 
    // Turn on WS_EX_COMPOSITED
   return cp;
   }
}

VB .net:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
 Get
    Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000  
    Return cp 
  End Get
 End Property
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top