C# WINDOWS MAUI專案 即時顯示系統時間(Timer Show Now Time)

C# WINDOWS MAUI專案 即時顯示系統時間(Timer Show Now Time)

C# WINDOWS MAUI專案 即時顯示系統時間(Timer Show Now Time)


資料來源: ChatGPT: C# maui show time in label


GITHUB: https://github.com/jash-git/MAUI_WinAPI_Object_test/tree/main/Code/02


code:

    public IDispatcherTimer timmer { get; set; }
    public MainPage()
    {
        InitializeComponent();

        //---
        //Timer Mode
        //https://learn.microsoft.com/en-us/answers/questions/1207012/how-to-stop-device-starttimer
        timmer = Application.Current.Dispatcher.CreateTimer();
        timmer.Interval = new TimeSpan(0, 0, 0, 0, 100);//天/時/分/秒/毫秒
        timmer.Tick += Timmer_Tick;
        timmer.IsRepeating = true;//the timer will keep recurring, you can set false
        timmer.Start();
        //---Timer Mode

    }
    private void Timmer_Tick(object sender, EventArgs e)
    {
        labtime.Text = DateTime.Now.ToString("HH:mm:ss");
    } //timmer.Stop(); 

One thought on “C# WINDOWS MAUI專案 即時顯示系統時間(Timer Show Now Time)

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *