winform.controls icon indicating copy to clipboard operation
winform.controls copied to clipboard

采用双缓冲,解决自定控件闪烁问题

Open yzhbest opened this issue 4 years ago • 0 comments

优化BaseForm的OnPaint函数 protected override void OnPaint(PaintEventArgs e) { //Graphics g = e.Graphics; //GDIHelper.InitializeGraphics(g); //this.DrawFormBackGround(g); //this.DrawCaption(g); //this.DrawFormBorder(g);

        //缓冲
        BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
        BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
        Graphics g = myBuffer.Graphics;
        GDIHelper.InitializeGraphics(g);
        this.DrawFormBackGround(g);
        this.DrawCaption(g);
        this.DrawFormBorder(g);

        g.SmoothingMode = SmoothingMode.HighQuality;
        g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
        myBuffer.Render(e.Graphics);
        g.Dispose();
        myBuffer.Dispose();//释放资源
    }

yzhbest avatar May 09 '20 10:05 yzhbest