Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:15:58+00:00 2026-06-18T10:15:58+00:00

i have maded a counter which is a simple counter which starts from 00:00:00

  • 0

i have maded a counter which is a simple counter which starts from 00:00:00 and incremented in every seconds
i will provide my code for that

in the form load event i have written this

 private DateTime startTime; 
        private void Form7_Load(object sender, EventArgs e)
        {
            startTime = DateTime.Now; 
            timer1.Start();

        }

 private void timer1_Tick(object sender, System.EventArgs e)
            {

                counter_label.Text = (DateTime.Now - startTime)
.ToString(@"hh\:mm\:ss");
            }

the timer is set to 1000 means to 1 seconds so my timer works fine
but now i want to save the label.text to the setting of the winform which is located in the properties.settings.default
so i saved the text to that by

private void Form7_FormClosing(object sender, FormClosingEventArgs e)
        {

            DateTime st;
            DateTime end;
            st = Convert.ToDateTime(Properties.Settings.Default.datetime);
            end = Convert.ToDateTime(counter_label.Text);

            Properties.Settings.Default.datetime = counter_label.Text;
          total_label.Text = (st + end ).ToString(@"hh\:mm\:ss");// this is not happening

          Properties.Settings.Default.datetime = total_label.Text;
            Properties.Settings.Default.Save();
        }

the error is operand + cannot be applied to system.datetime and system.datetime
my intention is. when i save the text to the system properties. at the form closing event, the new updated result must be saved which is. the old text from the system.properties and the new fromt the counter_label. how can it be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:15:59+00:00Added an answer on June 18, 2026 at 10:15 am

    Do not use setting of string type to store TimeSpan object (as Habib already stated, subtraction or addition of DateTime objects produces TimeSpan). You should create settings of type System.TimeSpan in Settings.settings file (e.g. with name TotalTime).

    Saving:

    Properties.Settings.Default.TotalTime = (DateTime.Now - startTime);
    Properties.Settings.Default.Save();
    

    Loading (here is trick – you are subtracting time which left from current time. So, if you have two minutes left, start time will be set for two minutes before you started applicatioin, like you never closed it):

    startTime = DateTime.Now.Subtract(Properties.Settings.Default.TotalTime);
    

    So, you don’t need parsing any strings. Work with DateTime and TimeSpan, and let .NET to do all persisting work for you.


    UPDATE (all code):

    DateTime startTime;
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        label1.Text = (DateTime.Now - startTime).ToString(@"hh\:mm\:ss");
    }
    
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        timer1.Stop();
        Properties.Settings.Default.TotalTime = (DateTime.Now - startTime);
        Properties.Settings.Default.Save();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
        startTime = DateTime.Now.Subtract(Properties.Settings.Default.TotalTime);
        timer1.Start();
    }
    

    If it is first run of your application, then Properties.Settings.Default.TotalTime will return default value of TimeSpan (which is zero time span). So, subtracting it from current time will return same value as current time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a code that read data from flash Nand (without filesystem). fd
I have the following code which is an implementation of BPM (bipartite matching, from
I have made a simple realtime visitor counter. You can download it from this
Hi i have a textbox which i am using as a counter to show
I have a master file which is the one which will constantly be updated
So I have a gauge that I've made that will be animating in either
I currently have some code which needs to perform multiple updates per user for
I have implemented a page hit counter which counts the number of page views
I'm writing a program that will guess words taken from a big text file.
I have the following problem in Cakephp: I maded a CMS to edit the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.