Results 1 to 3 of 3

Thread: [2005] updating ToolStripStatusLabel1 from a 2nd form

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    [2005] updating ToolStripStatusLabel1 from a 2nd form

    Hi Guys

    I have 2 forms.

    Main_form has a StatusStrip1 with ToolStripStatusLabel1 I would like to update this label with lat and Long information

    GPS form contains the serial port and all the GPS information
    when ever I get a new GPS message I call public sub Update_status_bar
    located in main_form

    I don't get any errors but no data in the ToolStripStatusLabel1


    Public Sub update_status_bar()

    Dim temp As String

    temp = Lat_Dec & " " & Long_Dec
    SetTextBoxText(temp)

    End Sub

    Public Delegate Sub SetTextBoxTextDelegate(ByVal text As String)

    public Sub SetTextBoxText(ByVal text As String)

    If Me.StatusStrip1.InvokeRequired Then
    'This is a worker thread so create a delegate to cross the thread boundary.
    Me.StatusStrip1.Invoke(New SetTextBoxTextDelegate(AddressOf SetTextBoxText), ToolStripStatusLabel1.Text = text)
    Else
    'This is the UI thread so access the control's members directly.
    Me.ToolStripStatusLabel1.Text = text

    End If
    Me.StatusStrip1.Refresh()

    End Sub

    any Ideas?
    Last edited by Glenozzy; Feb 17th, 2007 at 11:16 AM.

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] updating ToolStripStatusLabel1 from a 2nd form

    My guess is that you are just calling Update_Status_Bar and not using a reference to your existing instance of Main_form. I would suggest that you create a Property in the 2nd form called MyParent and before you Show the 2nd form, pass in the reference to Main_form.

    For Example:
    Main_form code
    VB Code:
    1. Dim frm as New frmSecondForm
    2.  
    3.     With frm
    4.         .MyParent = Me
    5.         .ShowDialog()
    6.         .Dispose()
    7.     End With

    frmSecondForm code
    VB Code:
    1. Private _MyParent As Form
    2.  
    3.     Private WriteOnly Property MyParent() As Form
    4.         Set(ByVal value As Form)
    5.             _MyParent = value
    6.         End Set
    7.     End Property
    8.  
    9.     Private Sub UpdateParentStatus()
    10.         _MyParent.ToolStripStatusLabel1.Text = Lat_Dec & " " & Long_Dec
    11.     End Sub
    My.Settings.Signature = String.Empty

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Re: [2005] updating ToolStripStatusLabel1 from a 2nd form

    Main_Form Call

    Private Sub GPSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GPSToolStripMenuItem.Click

    Dim frm As New GPS
    With frm
    .MyParent = Me
    .ShowDialog()
    .Dispose()
    End With

    GPS.Visible = True

    End Sub

    If I enter the code like this I get the following error

    Public _MyParent As Main_Form

    Public WriteOnly Property MyParent() As Form
    Set(ByVal value As Form)
    _MyParent = value
    End Set
    End Property

    Private Sub UpdateParentStatus()
    _MyParent.ToolStripStatusLabel1.Text = "Messages Received Acquiring"


    End Sub

    A first chance exception of type 'System.NullReferenceException' occurred in NO_Name1.exe



    Public _MyParent As Form

    Public WriteOnly Property MyParent() As Form
    Set(ByVal value As Form)
    _MyParent = value
    End Set
    End Property

    Private Sub UpdateParentStatus()
    _MyParent.ToolStripStatusLabel1.Text = "Messages Received Acquiring GPS"


    End Sub


    and on this way I get ToolStripStatusLabel1 is not a member

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