[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?
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:
Dim frm as New frmSecondForm
With frm
.MyParent = Me
.ShowDialog()
.Dispose()
End With
frmSecondForm code
VB Code:
Private _MyParent As Form
Private WriteOnly Property MyParent() As Form
Set(ByVal value As Form)
_MyParent = value
End Set
End Property
Private Sub UpdateParentStatus()
_MyParent.ToolStripStatusLabel1.Text = Lat_Dec & " " & Long_Dec
End Sub
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