Open a URL from Windows Forms

前端 未结 6 1053
小蘑菇
小蘑菇 2020-11-27 06:35

I\'m trying to provide a link to my company\'s website from a Windows Form. I want to be well behaved and launch using the user\'s preferred browser.

What is the be

6条回答
  •  盖世英雄少女心
    2020-11-27 07:06

    Here is the best of both worlds:

    Dim sInfo As New ProcessStartInfo("http://www.mysite.com")
    
    Try
         Process.Start(sInfo)
    Catch ex As Exception
         Process.Start("iexplore.exe", sInfo.FileName)
    End Try
    

    I found that the answer provided by Blorgbeard will fail when a desktop application is run on a Windows 8 device. To Camillo's point, you should attempt to open this with the user's default browser application, but if the browswer application is not assigned, an unhandled exception will be thrown.

    I am posting this as the answer since it handles the exception while still attempting to open the link in the default browser.

提交回复
热议问题