Author Topic: Show Ip adrress when form loads  (Read 1304 times)

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Show Ip adrress when form loads
« on: January 05, 2015, 10:07:59 PM »
 I put a label on my form  and would like it to show the driver address when the form loads and maybe also have it change automatically if I change the driver IP via a button ,

this works ok to show the Ip address , but I have to click on it to show the Ip address

Private Sub BasicLabel18_Click(sender As System.Object, e As System.EventArgs) Handles BasicLabel18.Click
        BasicLabel18.Text = EthernetIPforPLCSLCMicroCom1.IPAddress
    End Sub

thanks Darrell

Godra

  • Hero Member
  • *****
  • Posts: 1439
    • View Profile
Re: Show Ip adrress when form loads
« Reply #1 on: January 05, 2015, 10:28:31 PM »
For Main Form you could use the load event (double click the Main Form and it should show right away):

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BasicLabel18.Text = EthernetIPforPLCSLCMicroCom1.IPAddress
    End Sub

The way I am thinking, a timer added to the form could work as well and should be updating the label text property for the interval specified (like 1000 or 2000 milliseconds).

Archie might have better answer anyway.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5271
    • View Profile
    • AdvancedHMI
Re: Show Ip adrress when form loads
« Reply #2 on: January 06, 2015, 08:13:06 AM »
I'll show you a little bit of an advanced method that will also give you some insight into .NET component building.

- Open EthernetIPforPLCSLCMicroCom.vb and go to line 55
- Add this line of code to declare a new event:
Public Event IPAddressChanged As EventHandler

- Go to line 191 (just before the End If) and add this line of code:
OnIPAddressChanged

-Go all the way to the bottom just one line before "End Class" and add this code:
Protected Overridable Sub OnIPAddressChanged()
    RaiseEvent IPAddressChanged(Me, System.EventArgs.Empty)
End Sub

- Go to Window->Close All Documents (just a safety measure to prevent from crashing Visual Studio)
- Build->Rebuild Solution


The driver will now have a new Event that you can use on your form.

- Select the driver instance on your form
- In the Properties Window, click the lightening bolt
- You should now see IPAddressChanged, double click to get to the code for the event handler

Darrell

  • Full Member
  • ***
  • Posts: 198
  • Electrician / PLC Technician
    • View Profile
Re: Show Ip adrress when form loads
« Reply #3 on: January 06, 2015, 11:26:11 AM »
Cool , will give it a try
Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5271
    • View Profile
    • AdvancedHMI
Re: Show Ip adrress when form loads
« Reply #4 on: January 07, 2015, 06:29:15 PM »
Version 3.97 is now posted that has this new event as part of the driver.