绘制对象并在面板上更新其位置而不闪烁

  • 本文关键字:位置 闪烁 更新 对象 绘制 c#
  • 更新时间 :
  • 英文 :


我想避免闪烁,我也不想使用计时器。有没有一种方法可以代替计时器来代替计时器来更新表单或刷新图形?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test
{
    public partial class Form1 : Form
    {
        SolidBrush sb = new SolidBrush(Color.White);
        Pen p = new Pen(Color.LightGray, 3);
        Graphics g;  
        int xpos;
        int ypos;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            g = panel1.CreateGraphics();
            this.DoubleBuffered = true;  
        }    
        void Draw(string Shape, int x, int y)
        {
            panel1.Invalidate();
            switch (Shape)
            {
                case "Circle":
                    g.FillEllipse(sb, x, y, 20, 20);
                    g.DrawEllipse(p, x, y, 20, 20);
                    break;
            }  
        }
        private void tmrAnimaion_Tick(object sender, EventArgs e)
        {
            xpos += 2;
            Draw("Circle", xpos, ypos);
            if (xpos >= 700)
            {
                xpos = 0;
                ypos += 20;
            }
        }
    }
}

你能在 Paint 或 OnPaint() 中画画吗?

C# WinForms - 绘制方法问题

在 Winforms 中自定义控件绘制的最佳实践?

WinForms 绘制周期文档?

最新更新