|
-
Jun 20th, 2007, 03:45 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Digital clock
hi guys! what is the best way to put a digital clock in a windows application? because currently the code below is my solution but i dont know if that is the best way or the right way to do that...any suggestions will be greatly appreciated..thanks in advance!
Code:
private void TimerClock_Tick(object sender, EventArgs e)
{
lblDateTime.Text = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
}
-
Jun 20th, 2007, 04:53 AM
#2
Re: Digital clock
What you've got is fine if you want to use the date and time formats specified in the current regional settings, although the following is a bit more succinct:
C# Code:
lblDateTime.Text = String.Format("{0:d} {0:T}", DateTime.Now);
On a different note, can I suggest some consistency in your variable names? If you're going to name a Label "lblDateTime" then surely you should name the Timer "tmrClock". If you're going to name the Timer "TimerClock" then surely you should name the Label "LabelDateTime". Frankly, I think Hungarian notation is pointless and I would name them "clockLabel" and "clockTimer".
-
Jun 20th, 2007, 06:49 AM
#3
Thread Starter
Fanatic Member
Re: Digital clock
Thanks JM and thanks for that suggestion. I'll put that in mind. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|