如何使用计时器在 visual studio 上顺序绘制 3 条线?

How draw 3 lines sequentially on visual studio using timer?

我希望这个简单的演示程序以 500 毫秒的间隔绘制 3 条线[(即绘制第一行(暂停间隔 500 毫秒),绘制第二行(暂停间隔 500 毫秒),绘制第三行,最后停止计时器 1 ].

我已经在 visual studio 上相应的(timer1 属性 行为间隔)字段中输入了值 500 毫秒。现在demo程序确实画了三条线,但是500毫秒的间隔是不行的(很明显是因为void timer1_Tick.

中缺少代码
namespace WindowsFormsApp44

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    Graphics g;
    Pen p;

    private void Form1_Load(object sender, EventArgs e)
    {
        g = this.CreateGraphics();
        p = new Pen(Color.Red, 5);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        timer1.Start();
        g.DrawLine(p, 200, 200, 300, 100);
        g.DrawLine(p, 300, 100, 400, 200);
        g.DrawLine(p, 200, 200, 400, 200);
        timer1.Stop();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {

    }
}
}

尝试这样的事情:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApp13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Graphics g;
        Pen p;
        int tickcount = 1;

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            g = this.CreateGraphics();
            p = new Pen(Color.Red, 5);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (tickcount)
            {
                case 1:
                    g.DrawLine(p, 200, 200, 300, 100);
                    break;

                case 2:
                    g.DrawLine(p, 300, 100, 400, 200);
                    break;

                case 3:
                    g.DrawLine(p, 200, 200, 400, 200);
                    break;

                default:
                    break;
            }
            tickcount++;
            if (tickcount > 3)
            {
                timer1.Stop();
                timer1.Enabled = false;
            }
        }
    }
}