Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to show the IP address so i make the IP address function:

VB
Function GetIP() As String
        Dim IP As New WebClient
        Return IP.DownloadString("http://bot.whatismyipaddress.com")
    End Function


Now, whenever the form load, it should shows me the IP address automatically instead of clicking the button manually to show the IP address.

I have done something this way but now working

VB
Private Sub Label29_Click_1(sender As Object, e As EventArgs) Handles IPAdd.Click
        Button3.PerformClick()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        IPAdd.Text = GetIP()  'Label name IPAdd
    End Sub


Please help
Posted

1 solution

Create a load method and add a call to the GetIP function from the load method:
VB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    IPAdd.Text = GetIP()

End Sub

There is no need to click the button.
You may want to look into delegates too as populating a textbox from the form thread is not generally considered good practice.
 
Share this answer
 
Comments
Member 11927641 7-Sep-15 2:43am    
sh*t.. my dumb way to adding that code in wrong load, now it is working fine... Thanks mate..
GuyThiebaut 7-Sep-15 2:49am    
We all have to start somewhere :)
Like I mentioned look into delegates too - it's a bit of a leap but it will set you in the right direction as directly referencing a control on the form from the form thread will lock the form.
This is not noticeable when you just update something once, however if you were to create a loop where you update a text box you would find that the form remains unresponsive until the loop ends.
Member 11927641 7-Sep-15 2:52am    
This is i noticed right now, when the form load, it remains unresponsive until it don't get the response from the IP server, is there anyway to do it in fast way. Can you able to tell a little bit more about delegates by using this ip address?
GuyThiebaut 7-Sep-15 3:11am    
This will get you started:

http://www.codeproject.com/Articles/31985/Updating-the-UI-from-a-thread-The-simplest-way

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900