Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yzhbest opened this issue May 9, 2020 · 0 comments
Open

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

yzhbest opened this issue May 9, 2020 · 0 comments

Comments

@yzhbest
Copy link

yzhbest commented May 9, 2020

优化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();//释放资源
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant