將 Tick 事件處理程式分配給 Timer

計時器中執行的所有操作都在 Tick 事件中處理。

public partial class Form1 : Form
{

    Timer myTimer = new Timer();

    
    public Form1()
    {
        InitializeComponent();

        myTimer.Tick += myTimer_Tick; //assign the event handler named "myTimer_Tick"
    }

    private void myTimer_Tick(object sender, EventArgs e)
    {
        // Perform your actions here.
    }
}