Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My question is, I have to open a URL by clicking on a button. This URL contains some variable and constant fields.

can anybody please give me code for this in vb.net

What I have tried:

My question is, I have to open a URL by clicking on a button. This URL contains some variable and constant fields.

can you please give me code for this in vb.net
Posted
Updated 26-Jan-23 3:09am
Comments
vblover Programmer 26-Jan-23 22:09pm    
U can Use WebBrowser Control to Navigate.
' Navigates to the URL in the address box when 
' the ENTER key is pressed while the ToolStripTextBox has focus.
Private Sub toolStripTextBox1_KeyDown( _
    ByVal sender As Object, ByVal e As KeyEventArgs) _
    Handles toolStripTextBox1.KeyDown
    If (e.KeyCode = Keys.Enter) Then
        Navigate(toolStripTextBox1.Text)
    End If

End Sub

' Navigates to the URL in the address box when 
' the Go button is clicked.
Private Sub goButton_Click( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles goButton.Click

    Navigate(toolStripTextBox1.Text)
End Sub
' Navigates to the given URL if it is valid.
Private Sub Navigate(ByVal address As String)
    If String.IsNullOrEmpty(address) Then Return
    If address.Equals("about:blank") Then Return
    If Not address.StartsWith("http://") And _
        Not address.StartsWith("https://") Then
        address = "http://" & address
    End If
    Try
        webBrowser1.Navigate(New Uri(address))
    Catch ex As System.UriFormatException
        Return
    End Try
End Sub
' Updates the URL in TextBoxAddress upon navigation.
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
    ByVal e As WebBrowserNavigatedEventArgs) _
    Handles webBrowser1.Navigated
    toolStripTextBox1.Text = webBrowser1.Url.ToString()
End Sub

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser?view=windowsdesktop-7.0

Create a new ProcessStartInfo object with the target URL as the command argument and set ShellExecute to True.
VB
Dim URL as String="http://www.CodePrject.Com"
Dim NewProcess As Diagnostics.ProcessStartInfo = New Diagnostics.ProcessStartInfo(URL)
NewProcess.UseShellExecute=True
Diagnostics.Start(NewProcess)
'If you need to block until the process exits, uncomment the following line
'NewProcess.WaitForExit()
 
Share this answer
 
Dim url As String = "http://www.kgm.in"

Process.Start(url)
 
Share this answer
 

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