Very sharp method to prevent the flickering of Custom User Controls

Source: Internet
Author: User

Recently, when developing a winform system, we used a large number of Custom User Controls, fully applied object-oriented methods, and used domain-driven design and development methods. In the early stage of this method, a large number of Custom User Controls were developed. As a result, these controls were placed on the form when running, and flickering was found on the switching interface. The more controls, the more powerful the flickering. After searching for a long time, I finally found this method, which is very sharp and effective. Paste it here. Thanks to the original author.

The solution is to rewrite createparams on form and usercontrol. The program is as follows,

Code on Form

C #

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

VB

Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
    Get
        Dim cp As CreateParams = MyBase.CreateParams
        cp.ExStyle = cp.ExStyle Or &H2000000
        ' Turn on WS_EX_COMPOSITED
        Return cp
    End Get
End Property

 

Usercontrol code

C #

protected override CreateParams CreateParams {
  get {
    var parms = base.CreateParams;
    parms.Style &= ~0x02000000;  // Turn off WS_CLIPCHILDREN
    return parms;
  }
}

VB

Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
    Get
        Dim parms As System.Windows.Forms.CreateParams = MyBase.CreateParams
        'Turn off WS_CLIPCHILDREN
        parms.Style = (parms.Style And (Not &H2000000))
        Return parms
    End Get
End Property

Exam materials: How
To fix the flickering in user controls

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.