Refresh form?

rbc827

Member
Joined
May 7, 2007
Messages
17
Programming Experience
Beginner
How do I refresh a form after an event? I have a box that shows my computers IP Address, a button to release the IP, and another button to renew the IP.

The way the code works now is that if you hit the RELEASE IP button, it will run ipconfig /release and then have to run the DISPLAY IP ADDRESS code. The same works with the renew button.

I would like to be able to have the code simply Me.Refresh() after it runs ipconfig /release or /renew. I tried this and it doesn't work.
 
No. Once the IPCONFIG /release command has ended, I want my IP ADDRESS label to be updated showing 0.0.0.0 or the 127.0.0.1

I want the same thing for the Renew. Once the command has completed, I want my form to refresh to show the new IP.
 
I think myProcess.WaitForExit() is what you need.. Start your process, then call that, and code will halt until the process exits. Recommend using the overload that has a timeout
 
Sorry, but that's not what I'm asking for. The IP Config will exit fine, but my form will not reload or refresh with the new information showing up on the label.
 
Here is my code now as it sits.

VB.NET:
Dim ipConfig As Process
        Dim oneLine As String
        Dim lineParts() As String

        ipConfig = New Process()
        ipConfig.StartInfo.FileName = "ipConfig.exe"

        ipConfig.StartInfo.Arguments = "/renew"
        ipConfig.StartInfo.UseShellExecute = False
        ipConfig.StartInfo.RedirectStandardOutput = True
        ipConfig.StartInfo.CreateNoWindow = True
        ipConfig.Start()

        Do While Not ipConfig.StandardOutput.EndOfStream
            oneLine = ipConfig.StandardOutput.ReadLine()
            If (Trim(oneLine) = "") Then Continue Do

            If (oneLine = oneLine.TrimStart) Or (InStr(oneLine, ":") = 0) Then
                LogMessage1(oneLine.Trim)
            Else
                lineParts = (oneLine.Trim.Split(":"c))
                lineParts(0) = Replace(lineParts(0), ". ", "")
                lineParts(1) = lineParts(1).Trim
                LogMessage1(vbTab & lineParts(0) & ":" & lineParts(1))

            End If
        Loop
        ipConfig.WaitForExit()
        ipConfig.Dispose()

        Dim myWorkstation As String = System.Net.Dns.GetHostName()
        Dim IPAddress As String = System.Net.Dns.GetHostEntry(myWorkstation).AddressList(0).ToString()
        Me.Label36.Text = IPAddress

        '--- Network Connectivity ----
        Dim Net As String = My.Computer.Network.IsAvailable
        If Net = True Then
            Me.Label38.Font = New Font("Arial", 8, FontStyle.Bold)
            Me.Label38.Text = ("Yes")
        Else
            Me.Label38.Font = New Font("Arial", 8, FontStyle.Bold)
            Me.Label38.Text = ("No")
        End If


        '--- Internet Connectivity ----
        Try
            If Net = True Then
                Dim Int As String = My.Computer.Network.Ping("www.usa.gov")
                If Int = True Then
                    Me.Label39.Font = New Font("Arial", 8, FontStyle.Bold)
                    Me.Label39.Text = ("Yes")
                Else
                    Me.Label39.Font = New Font("Arial", 8, FontStyle.Bold)
                    Me.Label39.Text = ("No")
                End If
            Else
                Me.Label39.Font = New Font("Arial", 8, FontStyle.Bold)
                Me.Label39.Text = ("No")
            End If
        Catch ex As Exception
            Me.Label39.Font = New Font("Arial", 8, FontStyle.Bold)
            Me.Label39.Text = ("No")
        End Try
 
Last edited by a moderator:
It works fine, but it's too much. I want to reduce the code so it reads more like this:

VB.NET:
Dim ipConfig As Process
        Dim oneLine As String
        Dim lineParts() As String

        ipConfig = New Process()
        ipConfig.StartInfo.FileName = "ipConfig.exe"

        ipConfig.StartInfo.Arguments = "/renew"
        ipConfig.StartInfo.UseShellExecute = False
        ipConfig.StartInfo.RedirectStandardOutput = True
        ipConfig.StartInfo.CreateNoWindow = True
        ipConfig.Start()

        Do While Not ipConfig.StandardOutput.EndOfStream
            oneLine = ipConfig.StandardOutput.ReadLine()
            If (Trim(oneLine) = "") Then Continue Do

            If (oneLine = oneLine.TrimStart) Or (InStr(oneLine, ":") = 0) Then
                LogMessage1(oneLine.Trim)
            Else
                lineParts = (oneLine.Trim.Split(":"c))
                lineParts(0) = Replace(lineParts(0), ". ", "")
                lineParts(1) = lineParts(1).Trim
                LogMessage1(vbTab & lineParts(0) & ":" & lineParts(1))

            End If
        Loop
        ipConfig.WaitForExit()
        ipConfig.Dispose()


Form.Refresh()
 
Last edited by a moderator:
Sorry, but that's not what I'm asking for. The IP Config will exit fine
I dont doubt it

but my form will not reload or refresh with the new information showing up on the label.
Indeed, but why should it? What is it that is intrinsically artificially intelligent about a form that makes it think "Oh, the system IP address has changed, I'll just check to see if any labels are showing it and then update them?"

Nothing

See, the exiting of IPConfig is an event after which point in time you are going to want to refresh those values yourself. What's the best way to be notified that IPConfig has exited, but to wait for it before moving on?
 
I don't understand what you are saying. Isn't there a function that I can run that will refresh my form as if I hit the F5 key?
 
I'm lost. How can this be such a hard concept to understand?

You have a form.
You have a label.
You get the IP as a string, and put it in the label. (You did that, by saying label1.Text = my_ip_or_whatever)

What is it in your mind that makes you think that a computer is artificially intelligent enough to automatically realise that a) the system ip address has changed and b) that your label is showing a string representation of it and it hence needs updating?

Just update your label again. You do it. Yourself. Not the system. You, the programmer. In code. After IPConfig finishes. Again, you say label1.Text = your_new_ip_or_whatever

Pressing F5 is for web browsers, to refresh webpages, not windows forms.
 
I'm lost. How can this be such a hard concept to understand?

You have a form.
You have a label.
You get the IP as a string, and put it in the label. (You did that, by saying label1.Text = my_ip_or_whatever)

What is it in your mind that makes you think that a computer is artificially intelligent enough to automatically realise that a) the system ip address has changed and b) that your label is showing a string representation of it and it hence needs updating?

Just update your label again. You do it. Yourself. Not the system. You, the programmer. In code. After IPConfig finishes. Again, you say label1.Text = your_new_ip_or_whatever

Pressing F5 is for web browsers, to refresh webpages, not windows forms.

I'm sorry, but I have to admit I chuckled a little with this one. Refreshing your form will only re-display the same data that was there. You can create a "Refresh" button, but all it will do is run exactly what you have already written there and then re-update the label. YOU have to update the label though.

Alternatively, if you want it to update once a second, then you can use the timer or something of the sort to run that function and update your label every XXXX milliseconds. Also you can code that in to the F5 button, if you really want to be able to hit F5 to update it or even check it.
 
I think finally we are coming to an understanding on what it is I'm trying to accomplish.

What you are saying is that the Form.Refresh() doesn't go through the entire form and repeat all the code again after the IP has been released. I HAVE to put the code for the label after the release of the IP to repeat the function.

Perhaps the timer function will work so that the label code runs every so many seconds. How do I do this? I only have 5 labels that would need to be refreshed every few seconds.

Thanks.
 
Back
Top