TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How To Create A Stop Watch In C#
Apurba Ranjan
Jul 25
2016
Code
1.1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
C# Code
using
System.Diagnostics;
Stopwatch st =
new
Stopwatch();
private
void
btnStart_Click(
object
sender, EventArgs e)
{
timer1.Start();
st.Start();
label2.Text =
"Start Time : "
+ DateTime.Now.ToLongTimeString();
}
private
void
btnStop_Click(
object
sender, EventArgs e)
{
timer1.Stop();
TimeSpan ts = st.Elapsed;
label1.Text =
"Duration : "
+ ts.ToString();
st.Stop();
label3.Text =
"End Time : "
+ DateTime.Now.ToLongTimeString();
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
label4.Text = DateTime.Now.ToLongTimeString();
}
Stop Watch
C#