Recently, in the course of project development, the Panel control was used to display the seat background, and the background image would blink when the split screen was toggled. With the help of colleagues, the following methods are resolved:
Create a new class, Inherit the Panel control class, then turn on the control's double-secondary buffer, and prohibit erasing the background, see the code:
1. Create a new Newpanel class to continue the Panel control class
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Diagnostics;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Namespace XC. Contorl
{
<summary>
Purpose: Prevents panel flicker
</summary>
public partial class Newpanel:panel
{
Public Newpanel ()
{
InitializeComponent ();
This. doublebuffered = true;//Set this form
SetStyle (Controlstyles.userpaint, true);
SetStyle (Controlstyles.allpaintinginwmpaint, true); Erase background is forbidden.
SetStyle (Controlstyles.doublebuffer, true); Double buffering
}
Public Newpanel (IContainer container)
{
Container. ADD (this);
InitializeComponent ();
This. doublebuffered = true;//Set this form
SetStyle (Controlstyles.userpaint, true);
SetStyle (Controlstyles.allpaintinginwmpaint, true); Erase background is forbidden.
SetStyle (Controlstyles.doublebuffer, true); Double buffering
}
}
}
2. Referencing the new Panel control class
In InitializeComponent (), add the following code:
This. Panel1 = new XC. Contorl.newpanel (this.components);
Through the above FA can solve the picture flicker problem, there are errors or shortcomings, hope to criticize correct!
C # winform Resolves an issue that flashes when a picture is refreshed in a Panel control