Network Availability _+ Main Form Status Bar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If the network cable is unplugged I need to change an image on my main form
status bar, however this does not work

' The computer has been connected or disconnected from the network
If e.IsNetworkAvailable = False Then
My.Forms.MainForm.usbtest.Panels(2).Appearance.Image =
My.Resources.server_error
Else
My.Forms.MainForm.usbtest.Panels(2).Appearance.Image =
My.Resources.server_ok
End If

If I put the following in the main form load it works fine
usbtest.Panels(2).Appearance.Image = My.Resources.server_ok
 
My guess is since the network is available the logic in
MyApplication_NetworkAvailability does not fire as my code acted the same as
yours.



Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As
Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs)
Handles Me.NetworkAvailabilityChanged
SetConnectionStatus(e.IsNetworkAvailable)
End Sub
Public Sub SetConnectionStatus(ByVal connected As Boolean)
If Not (connected) Then
frmMainForm.ToolStripStatusLabel1.Image = My.Resources.NetDown
Else
frmMainForm.ToolStripStatusLabel1.Image = My.Resources.NetUp
End If
End Sub



Private Sub frmMainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If My.Computer.Network.IsAvailable Then
ToolStripStatusLabel1.Image = My.Resources.NetUp
Else
ToolStripStatusLabel1.Image = My.Resources.NetDown
End If
End Sub
 
Back
Top