C # winform Resolves an issue that flashes when a picture is refreshed in a Panel control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.