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

时间:2012-12-13 07:35:13

标签: c# .net winforms system.drawing

应用程序中,我使用的是用户控件(名为panel),我正在此面板上绘图。 但是我已经使用了双缓冲

public Panel()
{            
    //double-buffering
    SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    SetStyle(ControlStyles.DoubleBuffer, true);
    SetStyle(ControlStyles.UserPaint, true);
    SetStyle(ControlStyles.ResizeRedraw, true); 
}

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

另外,我正在进行多项计算,计算Paint()中要填充的区域。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我不知道这是否有用。但是当我直接使用Invalidate方法和OnPaint事件而不是Paint时,我不会眨眼,(DoubleBuffering = true):

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();
    }
}
相关问题