0

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

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;
            }
        }
    }
}
4

1 回答 1

0

你能在 Paint 或 OnPaint() 中绘图吗?

C# WinForms - 绘制方法问题

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

WinForms 绘制周期文档?

于 2012-11-26T02:49:28.137 回答