Set start time for Stopwatch program in C#

后端 未结 5 2227
粉色の甜心
粉色の甜心 2021-01-06 09:29

I want to write a simple stopwatch program, I can make it work with the following code

    public Form1()
    {
        InitializeComponent();
    }
    Syst         


        
5条回答
  •  孤街浪徒
    2021-01-06 09:48

    is the offset fixed or variable?

    In either case, have it as some member variable or const for the class and just add it.

    private TimeSpan offset = TimeSpan.FromSeconds(45);
    

    Then just change your tick to include it:

    var combined = ss.Elapsed + offset;
    int hrs = combined.Hours, mins = combined.Minutes, secs = combined.Seconds;
    

提交回复
热议问题