簡體   English   中英

鼠標移動時C#屏幕閃爍

[英]C# Screen flickers on Mouse Move

應用程序中,我正在使用用戶控件(名為panel ),並且正在此面板上繪圖。 但是我已經使用了雙緩沖

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 ):

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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM