Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
U

User 12723023

@User 12723023
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • C# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch
    U User 12723023

    Is there a better way to run the Stop Watch: Form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Diagnostics;

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

        // new instance of Stop Watch
        Stopwatch StopWatch = new Stopwatch();
        
        private void lblClock\_Click(object sender, EventArgs e)
        {
    
        }
    
        private void btnStart\_Click(object sender, EventArgs e)
        {
            // Button Start Checking if already started
            if (timer1.Enabled)
            {
                MessageBox.Show("Sorry you have already started the Timer");
            }
    
            else
                 timer1.Start();
                 this.StopWatch.Start();
        }
    
        private void btnStop\_Click(object sender, EventArgs e)
        {
            // Button Stop Checking if already Stopped
            if (timer1.Enabled)
            {
                timer1.Stop();
                StopWatch.Stop();
            }
            else
                MessageBox.Show("Timer Already Stopped");
        }
    
        private void btnPause\_Click(object sender, EventArgs e)
        {
            // button reset
            StopWatch.Reset();
            lblClock.Text = "00 HR :00 MIN :00 SEC ";
        }
    
        private void timer1\_Tick(object sender, EventArgs e)
        {
    
            // Timer by hr min sec
             TimeSpan elapsed = this.StopWatch.Elapsed;
             lblClock.Text = string.Format("{0:00} HR :{1:00} MIN: {2:00} SEC", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds);
    
        }
    }
    

    }

    Class1.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Diagnostics;

    namespace StopWatch.BL
    {
    public class Time
    {
    Stopwatch stopwatch = new Stopwatch();

        public TimeSpan Elapsed // class elapsed
        {
            get { return stopwatch.Elapsed; }
        }
    
        public bool IsRunning // class is running
        {
            get { return stopwatch.IsRunning; }
        }
    
    
        public void Start() // start stop watch
    
    C# csharp linq graphics
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups