-
Apr 12th, 2006, 06:08 AM
#1
[RESOLVED] StatusBar shows DateTime, Time doesn't work.
Hi All,
I've created a StatusBar and several panels.
I can show the Date into my panel, but when I use the Time then it shows the Time static instead of Dynamic. My Timer is set Enable = true in the property and Interval = 1000.
I'm using a Timer for the Tick event but it isn't working.
Here's my code I'm using:
VB Code:
panel3.Text = System.DateTime.Now.ToShortTimeString()
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim panel3 As New StatusBarPanel
panel3.Text = System.DateTime.Now.ToShortTimeString()
End If
End Sub
Thanks in advance,
sparrow1
-
Apr 12th, 2006, 06:20 AM
#2
Re: StatusBar shows DateTime, Time doesn't work.
You are everytime creating a new instance of panel3. You should be using Dim here. Do it like this
VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
StatusBar1.Panels(0).Text = DateTime.Now.ToShortTimeString()
End Sub
Last edited by Shuja Ali; Apr 12th, 2006 at 06:23 AM.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 13th, 2006, 06:47 AM
#3
Re: StatusBar shows DateTime, Time doesn't work.
Originally Posted by Shuja Ali
You are everytime creating a new instance of panel3. You should be using Dim here. Do it like this
VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
StatusBar1.Panels(0).Text = DateTime.Now.ToShortTimeString()
End Sub
Hi,
It didn't solved my problem.
I forgot to tell you that I created a StatusBar by code and not in designtime!
Thanks,
sparrow1
-
Apr 13th, 2006, 08:50 AM
#4
Addicted Member
Re: StatusBar shows DateTime, Time doesn't work.
Shuja Ali still has it right though, if you're creating StatusBarPanes within a StatusBar, then you must refer to them by their index. If this is the third pane in the StatusBar, then it would be StatusBar.Panels(2).Text (or whatever you named your StatusBar)
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
Apr 13th, 2006, 09:43 AM
#5
Re: StatusBar shows DateTime, Time doesn't work.
Originally Posted by Isorfir
Shuja Ali still has it right though, if you're creating StatusBarPanes within a StatusBar, then you must refer to them by their index. If this is the third pane in the StatusBar, then it would be StatusBar.Panels(2).Text (or whatever you named your StatusBar)
Hi,
I think it's something strang.
Here's my code:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a StatusBar control.
Dim StatusBar1 As New StatusBar
' Create two StatusBarPanel objects to display in the StatusBar.
Dim panel1 As New StatusBarPanel
Dim panel2 As New StatusBarPanel
Dim panel3 As New StatusBarPanel
' Display the first panel with a sunken border style.
panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
' Initialize the text of the panel.
panel1.Text = "Ready..."
' Set the AutoSize property to use all remaining space on the StatusBar.
panel1.AutoSize = StatusBarPanelAutoSize.Spring
' Display the second panel with a raised border style.
panel1.ToolTipText = ("Ready")
panel2.BorderStyle = StatusBarPanelBorderStyle.Sunken
' Create ToolTip text that displays the current time.
panel2.ToolTipText = System.DateTime.Now.ToShortDateString()
' Set the text of the panel to the current date.
panel2.Text = System.DateTime.Now.ToShortDateString()
panel3.Text = System.DateTime.Now.ToShortTimeString()
panel3.ToolTipText = System.DateTime.Now.ToShortTimeString()
' Set the AutoSize property to size the panel to the size of the contents.
panel2.AutoSize = StatusBarPanelAutoSize.Contents
panel3.AutoSize = StatusBarPanelAutoSize.Contents
' Display panels in the StatusBar control.
StatusBar1.ShowPanels = True
' Add both panels to the StatusBarPanelCollection of the StatusBar.
StatusBar1.Panels.Add(panel1)
StatusBar1.Panels.Add(panel2)
StatusBar1.Panels.Add(panel3)
' Add the StatusBar to the form.
Me.Controls.Add(StatusBar1)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim StatusBar1 As New StatusBar
StatusBar1.Panels(3).Text = DateTime.Now.ToShortTimeString()
End Sub
I hope you can help me with it.
I've made another one in designtime and that works very Oke, but I'm curious
how to let it work with a StatusBar created with code.
Wkr,
sparrow1
-
Apr 13th, 2006, 09:54 AM
#6
Addicted Member
Re: StatusBar shows DateTime, Time doesn't work.
Haven't tested your code, but looks ok. But remember that index's are zero based. So, if you have 3 panels, then they are 0, 1, 2 respectively.
Originally Posted by sparrow1
VB Code:
StatusBar1.Panels(3).Text = DateTime.Now.ToShortTimeString()
Set that to:
VB Code:
StatusBar1.Panels(2).Text = DateTime.Now.ToShortTimeString()
Let me know if that works.
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
Apr 13th, 2006, 10:06 AM
#7
Re: StatusBar shows DateTime, Time doesn't work.
Sorry, But it didn't worked.
sparrow1
-
Apr 13th, 2006, 10:23 AM
#8
Addicted Member
Re: StatusBar shows DateTime, Time doesn't work.
Looks like I didn't examine your code close enough, I went ahead and tested it. Here's what you need to do:
These can not be local variables, because the Timer_Tick method can not access them.
VB Code:
Dim StatusBar1 As New StatusBar
Dim panel1 As New StatusBarPanel
Dim panel2 As New StatusBarPanel
Dim panel3 As New StatusBarPanel
Instead, at the top of your class, above all your Private Sub's put:
VB Code:
Public StatusBar1 As New StatusBar
Public panel1 As New StatusBarPanel
Public panel2 As New StatusBarPanel
Public panel3 As New StatusBarPanel
Making sure to delete the ones in your Form1_Load.
After you do that, it should work. All I had in my Timer_Tick method was:
VB Code:
StatusBar1.Panels(2).Text = System.DateTime.Now.ToShortTimeString()
And it works.
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
Apr 13th, 2006, 10:37 AM
#9
Re: StatusBar shows DateTime, Time doesn't work.
Originally Posted by Isorfir
Looks like I didn't examine your code close enough, I went ahead and tested it. Here's what you need to do:
These can not be local variables, because the Timer_Tick method can not access them.
VB Code:
Dim StatusBar1 As New StatusBar
Dim panel1 As New StatusBarPanel
Dim panel2 As New StatusBarPanel
Dim panel3 As New StatusBarPanel
Instead, at the top of your class, above all your Private Sub's put:
VB Code:
Public StatusBar1 As New StatusBar
Public panel1 As New StatusBarPanel
Public panel2 As New StatusBarPanel
Public panel3 As New StatusBarPanel
Making sure to delete the ones in your Form1_Load.
After you do that, it should work. All I had in my Timer_Tick method was:
VB Code:
StatusBar1.Panels(2).Text = System.DateTime.Now.ToShortTimeString()
And it works.
Thanks that works fine.
sparrow1
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
|