I want to design changing time on maskedtextbox in my application like windows where time changes on every second. I have set maskedtexbox1 as below:
maskedTextBox1.Text = DateTime.Now.ToShortTimeString();
which is showing current system short time but it’s not changing on every second like windows. How to do?
I’m on Visual Studio 2005, and .NET is below 3.5.
I’d use the timer and fire an event every second to update the time.
Timerin the package System.Windows.Forms).Kaboom).Somewhere in your executable code you do that by typing the following.
In the same class (or, if you’re confident how to do it, somewhere where you can reach the code) you also create the handler for the fired event of ticking, so that the promise you made about a method to be called when the timer goes off is kept.
Also, don’t forget to actually start your ticker when you feel that you’re ready.
Tada!
EDIT:
For the sake of completeness, I’m also going to paste in a part of the reply of @CuaonLe (a higher threshold of competence and requirement for .NET 3.5 or newer).