Click here to Skip to main content
15,867,756 members
Home / Discussions / C#
   

C#

 
AnswerRe: Polymorphism Pin
Nathan Minier14-Oct-16 1:56
professionalNathan Minier14-Oct-16 1:56 
QuestionHow to integrate Facebook marketing API in window application using c# Pin
Member 1063574713-Oct-16 3:11
Member 1063574713-Oct-16 3:11 
AnswerRe: How to integrate Facebook marketing API in window application using c# Pin
Eddy Vluggen13-Oct-16 3:38
professionalEddy Vluggen13-Oct-16 3:38 
QuestionHTMLtoPDF Downloader Pin
Member 1279065812-Oct-16 18:29
Member 1279065812-Oct-16 18:29 
AnswerRe: HTMLtoPDF Downloader Pin
Member 1279065812-Oct-16 18:41
Member 1279065812-Oct-16 18:41 
AnswerRe: HTMLtoPDF Downloader Pin
Nathan Minier13-Oct-16 3:13
professionalNathan Minier13-Oct-16 3:13 
AnswerRe: HTMLtoPDF Downloader Pin
yellow flower18-Oct-16 1:39
yellow flower18-Oct-16 1:39 
QuestionC# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch Pin
Member 1275660312-Oct-16 12:05
Member 1275660312-Oct-16 12:05 
Is there a better way to run the Stop Watch:

Form1.cs

C#
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
        {
           DateTime start = DateTime.Now;
           TimeSpan duration = DateTime.Now - start;
        }

        public void Stop() // stop the stop watch
        {
            
            stopwatch.Stop();
        }

        public void Reset() // reset the stop watch
        {
            stopwatch.Reset();
        }

    }
}

AnswerRe: C# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch Pin
Midi_Mick12-Oct-16 19:05
professionalMidi_Mick12-Oct-16 19:05 
AnswerRe: C# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch Pin
OriginalGriff12-Oct-16 22:47
mveOriginalGriff12-Oct-16 22:47 
AnswerRe: C# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch Pin
Bernhard Hiller13-Oct-16 22:08
Bernhard Hiller13-Oct-16 22:08 
AnswerRe: C# Stopwatch - DateTime And Timer Tick - Is there a better way to run the Stopwatch Pin
omeecode15-Oct-16 8:56
omeecode15-Oct-16 8:56 
QuestionHTML.Kendo.ComboBox [Error: Object doesn't support property or method 'requestData'] Pin
Atul Shriram rane11-Oct-16 17:57
Atul Shriram rane11-Oct-16 17:57 
AnswerRe: HTML.Kendo.ComboBox [Error: Object doesn't support property or method 'requestData'] Pin
NotPolitcallyCorrect12-Oct-16 4:53
NotPolitcallyCorrect12-Oct-16 4:53 
GeneralRe: HTML.Kendo.ComboBox [Error: Object doesn't support property or method 'requestData'] Pin
Pete O'Hanlon12-Oct-16 4:59
subeditorPete O'Hanlon12-Oct-16 4:59 
GeneralRe: HTML.Kendo.ComboBox [Error: Object doesn't support property or method 'requestData'] Pin
NotPolitcallyCorrect12-Oct-16 5:47
NotPolitcallyCorrect12-Oct-16 5:47 
QuestionI have a search button and datagrid in c# and SQL Pin
antonio_dsanchez11-Oct-16 11:16
antonio_dsanchez11-Oct-16 11:16 
AnswerRe: I have a search button and datagrid in c# and SQL Pin
Dave Kreskowiak11-Oct-16 11:23
mveDave Kreskowiak11-Oct-16 11:23 
AnswerRe: I have a search button and datagrid in c# and SQL Pin
antonio_dsanchez11-Oct-16 11:31
antonio_dsanchez11-Oct-16 11:31 
GeneralRe: I have a search button and datagrid in c# and SQL Pin
Swinkaran11-Oct-16 16:00
professionalSwinkaran11-Oct-16 16:00 
GeneralRe: I have a search button and datagrid in c# and SQL Pin
Pete O'Hanlon11-Oct-16 20:35
subeditorPete O'Hanlon11-Oct-16 20:35 
QuestionClosest standard value Pin
Pavlex410-Oct-16 10:44
Pavlex410-Oct-16 10:44 
AnswerRe: Closest standard value Pin
Pete O'Hanlon10-Oct-16 19:31
subeditorPete O'Hanlon10-Oct-16 19:31 
GeneralRe: Closest standard value Pin
Pavlex410-Oct-16 23:38
Pavlex410-Oct-16 23:38 
Rant[REPOST] Closest standard value Pin
Richard Deeming11-Oct-16 2:14
mveRichard Deeming11-Oct-16 2:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.