|
-
Apr 10th, 2006, 03:43 AM
#1
Thread Starter
New Member
[RESOLVED] Help! Display Time in a Label (VB Express 2005)
Hello, newbie questions here.
I'm using VB 2005 Express.
I want to return the current time in Label2.
Current code:
VB Code:
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Label2.Text = Now.ToString("HH:MM")
The problem is I have to click the label at run-time on the form in order for the time to show.
How can set things up so the Time displays automatically when the form loads without me having to click the label first?
Also, how can I display GMT or Universal Time instead of system time?
Thanks for helping the newbie!
-
Apr 10th, 2006, 05:53 AM
#2
Re: Help! Display Time in a Label (VB Express 2005)
You posted this question to the wrong forum your should have posted this to the VB.Net forum. MOD Please move this post.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Apr 10th, 2006, 06:56 AM
#3
Re: Help! Display Time in a Label (VB Express 2005)
-
Apr 10th, 2006, 07:38 AM
#4
Lively Member
Re: Help! Display Time in a Label (VB Express 2005)
You have to click it because you have your code in the labels click event, put it in the forms load event instead.....like this
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = Now.ToString("HH:MM")
End Sub
VB.Net 2005 Express
.Net Framework 2.0
-
Apr 10th, 2006, 07:54 AM
#5
Re: Help! Display Time in a Label (VB Express 2005)
Generally you would add a Timer to your form and set its Interval to 1000 (milliseconds). You would then handle the Tick event of the Timer to update your Label so it always shows the current time:
VB Code:
'24 hour time, no seconds.
Me.Label1.Text = Date.Now.ToString("HH:mm") 'Note that the "mm" is lower case because upper case means month.
'Standard time format.
Me.Label1.Text = Date.Now.ToShortTimeString()
'GMT.
Me.Label1.Text = Date.Now.ToUniversalTime().ToShortTimeString()
-
Apr 10th, 2006, 01:36 PM
#6
Thread Starter
New Member
Re: Help! Display Time in a Label (VB Express 2005)
Thank you! She works, even got the timer in too so it updates the time.
-
Apr 10th, 2006, 07:20 PM
#7
Re: Help! Display Time in a Label (VB Express 2005)
Cool. Don't forget to resolve your thread from the Thread Tools menu.
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
|