首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >鼠标移动时C#屏幕闪烁

鼠标移动时C#屏幕闪烁
EN

Stack Overflow用户
提问于 2012-12-13 15:35:13
回答 1查看 1.4K关注 0票数 1

winforms应用程序中,我使用了一个名为panel的用户控件,并在此面板上进行绘图。但是,我已经使用了双缓冲

代码语言:javascript
复制
public Panel()
{            
    //double-buffering
    SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    SetStyle(ControlStyles.DoubleBuffer, true);
    SetStyle(ControlStyles.UserPaint, true);
    SetStyle(ControlStyles.ResizeRedraw, true); 
}

但是,当我填充屏幕上的任何形状时,屏幕仍会闪烁。

此外,我正在进行一些计算,计算要在Paint()中填充的区域。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-12-13 22:14:06

我不知道这是否有用。但是当我使用Invalidate方法和OnPaint事件而不是直接使用Paint (DoubleBuffering = true)时,我没有看到任何闪烁:

代码语言:javascript
复制
public partial class Form1 : Form
{
    private Graphics g = null;
    private Pen z = new Pen(new SolidBrush(Color.Blue));

    public Form1()
    {
        InitializeComponent();
        g = CreateGraphics();
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawLine(z, p, p2);
    }

    private Point p = new Point();
    private Point p2 = new Point();

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
            p = e.Location;

        p2 = e.Location;

        Invalidate();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13855108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档