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

Winforms C#鼠标移动时屏幕闪烁,winforms,c#,.net,system.drawing,Winforms,C#,.net,System.drawing,在应用程序中,我使用一个用户控件(名为面板),并在此面板上绘图。 然而,我已经使用了双缓冲 public Panel() { //double-buffering SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true);

在应用程序中,我使用一个用户控件(名为
面板
),并在此面板上绘图。 然而,我已经使用了双缓冲

public Panel()
{            
    //double-buffering
    SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    SetStyle(ControlStyles.DoubleBuffer, true);
    SetStyle(ControlStyles.UserPaint, true);
    SetStyle(ControlStyles.ResizeRedraw, true); 
}
但当我在屏幕上填充任何形状时,屏幕仍会闪烁

此外,我还进行了大量计算,计算了
Paint()
中要填充的区域


提前谢谢。

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


尝试将resize redraw offsee设置为“这可以显示OnPaint()事件背后的代码吗?无论您在做什么,都不应该在MouseMove事件处理程序中执行此操作。双缓冲只能在OnPaint()中绘制时起作用。@HansPassant:实际上我正在使用graphics.FillRegion(画笔,图形路径)来填充形状的路径。早些时候,当我不使用这种方法时,屏幕并没有闪烁。我试着调试,我正在填充的区域的“nativeRegion”值每次都在变化。
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();
    }
}