EDN Admin
Well-known member
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Collections.Generic;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.ComponentModel;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Data;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Drawing;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Linq;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Text;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Windows.Forms;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
namespace
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small TimerApp
{
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff public<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff partial<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff class<span style="font-size:x-small <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af Form1<span style="font-size:x-small : <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af Form
<span style="font-size:x-small
{
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff public<span style="font-size:x-small Form1()
{
InitializeComponent();
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small btnStop_Click_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small dateTime1, dateTime2;<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 // Change Time String to DateTime object
<span style="font-size:x-small <font size=2>
dateTime1 =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Parse(textBox1.Text);<font size=2>
dateTime2 =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Parse(textBox2.Text);<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Find the Difference
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af TimeSpan<span style="font-size:x-small timeDiff = dateTime2.Subtract(dateTime1);<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Display the Difference
<span style="font-size:x-small
textBox3.Text = timeDiff.ToString();
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Stop the Timer
<span style="font-size:x-small <font size=2>
tmrTime.Enabled =
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff false<span style="font-size:x-small ;
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small btnStart_Click_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Display the current Time
<span style="font-size:x-small <font size=2>
textBox1.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );<font size=2>
textBox2.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Start the Timer
<span style="font-size:x-small <font size=2>
tmrTime.Enabled =
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small ;
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small tmrTime_Tick_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Periodically update the values
<span style="font-size:x-small <font size=2>
textBox2.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );
}
}
}<br/><br/><br/><br/>This is a code that will display the current time in a textbox, will continue to display the time in a second textbox and will show the time difference in a third textbox when the stop button is pushed. however it is only displaying the difference in the format hh:mm:ss and i want it to display in milliseconds. can anyone help me to modify the code to do this?
View the full article
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Collections.Generic;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.ComponentModel;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Data;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Drawing;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Linq;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Text;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
using
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small System.Windows.Forms;
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff <font size=2 color="#0000ff <font size=2 color="#0000ff
namespace
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small TimerApp
{
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff public<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff partial<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff class<span style="font-size:x-small <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af Form1<span style="font-size:x-small : <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af Form
<span style="font-size:x-small
{
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff public<span style="font-size:x-small Form1()
{
InitializeComponent();
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small btnStop_Click_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small dateTime1, dateTime2;<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 // Change Time String to DateTime object
<span style="font-size:x-small <font size=2>
dateTime1 =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Parse(textBox1.Text);<font size=2>
dateTime2 =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Parse(textBox2.Text);<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Find the Difference
<span style="font-size:x-small <font size=2>
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af TimeSpan<span style="font-size:x-small timeDiff = dateTime2.Subtract(dateTime1);<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Display the Difference
<span style="font-size:x-small
textBox3.Text = timeDiff.ToString();
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Stop the Timer
<span style="font-size:x-small <font size=2>
tmrTime.Enabled =
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff false<span style="font-size:x-small ;
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small btnStart_Click_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Display the current Time
<span style="font-size:x-small <font size=2>
textBox1.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );<font size=2>
textBox2.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Start the Timer
<span style="font-size:x-small <font size=2>
tmrTime.Enabled =
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff true<span style="font-size:x-small ;
}
<font size=2>
</font>
<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff private<span style="font-size:x-small <span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff void<span style="font-size:x-small tmrTime_Tick_1(<span style="font-size:x-small;color:#0000ff <span style="font-size:x-small;color:#0000ff object<span style="font-size:x-small sender, <span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af EventArgs<span style="font-size:x-small e)
{
<font size=2>
</font>
<span style="font-size:x-small;color:#008000 <span style="font-size:x-small;color:#008000 //Periodically update the values
<span style="font-size:x-small <font size=2>
textBox2.Text =
</font>
<span style="font-size:x-small;color:#2b91af <span style="font-size:x-small;color:#2b91af DateTime<span style="font-size:x-small .Now.ToString(<span style="font-size:x-small;color:#a31515 <span style="font-size:x-small;color:#a31515 "hh:mm:ss.fff tt"<span style="font-size:x-small );
}
}
}<br/><br/><br/><br/>This is a code that will display the current time in a textbox, will continue to display the time in a second textbox and will show the time difference in a third textbox when the stop button is pushed. however it is only displaying the difference in the format hh:mm:ss and i want it to display in milliseconds. can anyone help me to modify the code to do this?
View the full article