Results 1 to 9 of 9

Thread: [RESOLVED] StatusBar shows DateTime, Time doesn't work.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Resolved [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:
    1. panel3.Text = System.DateTime.Now.ToShortTimeString()
    2.  
    3. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    4.         Dim panel3 As New StatusBarPanel
    5.         panel3.Text = System.DateTime.Now.ToShortTimeString()
    6.         End If
    7. End Sub

    Thanks in advance,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, _
    2.          ByVal e As System.EventArgs) Handles Timer1.Tick
    3.         StatusBar1.Panels(0).Text = DateTime.Now.ToShortTimeString()
    4.     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

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: StatusBar shows DateTime, Time doesn't work.

    Quote 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:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, _
    2.          ByVal e As System.EventArgs) Handles Timer1.Tick
    3.         StatusBar1.Panels(0).Text = DateTime.Now.ToShortTimeString()
    4.     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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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

  5. #5

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: StatusBar shows DateTime, Time doesn't work.

    Quote 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:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         ' Create a StatusBar control.
    4.         Dim StatusBar1 As New StatusBar
    5.         ' Create two StatusBarPanel objects to display in the StatusBar.
    6.         Dim panel1 As New StatusBarPanel
    7.         Dim panel2 As New StatusBarPanel
    8.         Dim panel3 As New StatusBarPanel
    9.  
    10.         ' Display the first panel with a sunken border style.
    11.         panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
    12.         ' Initialize the text of the panel.
    13.         panel1.Text = "Ready..."
    14.         ' Set the AutoSize property to use all remaining space on the StatusBar.
    15.         panel1.AutoSize = StatusBarPanelAutoSize.Spring
    16.         ' Display the second panel with a raised border style.
    17.         panel1.ToolTipText = ("Ready")
    18.         panel2.BorderStyle = StatusBarPanelBorderStyle.Sunken
    19.         ' Create ToolTip text that displays the current time.
    20.         panel2.ToolTipText = System.DateTime.Now.ToShortDateString()
    21.         ' Set the text of the panel to the current date.
    22.         panel2.Text = System.DateTime.Now.ToShortDateString()
    23.         panel3.Text = System.DateTime.Now.ToShortTimeString()
    24.         panel3.ToolTipText = System.DateTime.Now.ToShortTimeString()
    25.         ' Set the AutoSize property to size the panel to the size of the contents.
    26.         panel2.AutoSize = StatusBarPanelAutoSize.Contents
    27.         panel3.AutoSize = StatusBarPanelAutoSize.Contents
    28.         ' Display panels in the StatusBar control.
    29.  
    30.         StatusBar1.ShowPanels = True
    31.  
    32.         ' Add both panels to the StatusBarPanelCollection of the StatusBar.            
    33.         StatusBar1.Panels.Add(panel1)
    34.         StatusBar1.Panels.Add(panel2)
    35.         StatusBar1.Panels.Add(panel3)
    36.         ' Add the StatusBar to the form.
    37.         Me.Controls.Add(StatusBar1)
    38.  
    39.  
    40.     End Sub
    41.  
    42.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    43.         Dim StatusBar1 As New StatusBar
    44.         StatusBar1.Panels(3).Text = DateTime.Now.ToShortTimeString()
    45.  
    46.  
    47.     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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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.

    Quote Originally Posted by sparrow1
    VB Code:
    1. StatusBar1.Panels(3).Text = DateTime.Now.ToShortTimeString()
    Set that to:

    VB Code:
    1. StatusBar1.Panels(2).Text = DateTime.Now.ToShortTimeString()

    Let me know if that works.
    IDE: Visual Studio 2008/2010 - C# | VB.Net

  7. #7

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: StatusBar shows DateTime, Time doesn't work.

    Sorry, But it didn't worked.

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  8. #8
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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:
    1. Dim StatusBar1 As New StatusBar
    2.  
    3. Dim panel1 As New StatusBarPanel
    4. Dim panel2 As New StatusBarPanel
    5. Dim panel3 As New StatusBarPanel

    Instead, at the top of your class, above all your Private Sub's put:

    VB Code:
    1. Public StatusBar1 As New StatusBar
    2.     Public panel1 As New StatusBarPanel
    3.     Public panel2 As New StatusBarPanel
    4.     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:
    1. StatusBar1.Panels(2).Text = System.DateTime.Now.ToShortTimeString()

    And it works.
    IDE: Visual Studio 2008/2010 - C# | VB.Net

  9. #9

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,817

    Re: StatusBar shows DateTime, Time doesn't work.

    Quote 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:
    1. Dim StatusBar1 As New StatusBar
    2.  
    3. Dim panel1 As New StatusBarPanel
    4. Dim panel2 As New StatusBarPanel
    5. Dim panel3 As New StatusBarPanel

    Instead, at the top of your class, above all your Private Sub's put:

    VB Code:
    1. Public StatusBar1 As New StatusBar
    2.     Public panel1 As New StatusBarPanel
    3.     Public panel2 As New StatusBarPanel
    4.     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:
    1. StatusBar1.Panels(2).Text = System.DateTime.Now.ToShortTimeString()

    And it works.
    Thanks that works fine.

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width