Double buffering with Panel

后端 未结 3 1035
谎友^
谎友^ 2020-12-01 17:53

Double buffering the whole form can be done by setting the value of the \"AllPaintingInWmPaint\", \"UserPaint\" and \"DoubleBuffer\" ControlStyles to \"true\" (this.Se

3条回答
  •  感动是毒
    2020-12-01 18:10

    Use a PictureBox if you don't need scrolling support, it is double-buffered by default. Getting a double-buffered scrollable panel is easy enough:

    using System;
    using System.Windows.Forms;
    
    class MyPanel : Panel {
        public MyPanel() {
            this.DoubleBuffered = true;
            this.ResizeRedraw = true;
        }
    }
    

    The ResizeRedraw assignment suppresses a painting optimization for container controls. You'll need this if you do any painting in the panel. Without it, the painting smears when you resize the panel.

    Double-buffering actually makes painting slower. Which can have an effect on controls that are drawn later. The hole they leave before being filled may be visible for a while, also perceived as flicker. You'll find counter-measures against the effect in this answer.

提交回复
热议问题