2015-09-11 44 views
-2

我想創建一個按鈕,例如:[圍棋]。當我點擊它時,我的程序將啓動網絡瀏覽器並瀏覽一個網站。 例子:我點擊谷歌,下面的Web瀏覽器將顯示Google.com。 未點擊時,網頁瀏覽器無法運行。 我正在使用Visual Studio 2010,Winform C#應用程序。如何創建一個按鈕,當我點擊,網頁瀏覽器運行

+0

歡迎SO!你有代碼分享迄今爲止已經嘗試過的嗎?你卡在哪裏? – J0e3gan

+0

你好,我會在稍後與你分享。 – chicanpro

+0

看看使用https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser(v=vs.110).aspx] –

回答

1

這是因爲調用過程

Process.Start("chrome.exe", "http:\\www.example.com"); 

上面的例子是谷歌瀏覽器一樣簡單,你可以與其他瀏覽器嘗試過。

+0

感謝你,但我想用一個支持的Web瀏覽器在Visual Studio中。我在Toolbox中看到它。 – chicanpro

+0

你創建在Visual Studio工具欄按鈕,或者是你創建一個Visual Studio插件? – pushpraj

+1

'的Process.Start( 「http://www.example.com/」);'就足夠了。這將在默認瀏覽器中啓動它。 – vesan

1

我從你的問題理解什麼是你想創建一個按鈕,你點擊它會去寫在地址欄中的地址,而如果地址欄是空白的web瀏覽器會變成空白。

如果是這樣的話...此代碼可以幫助你..

private void GotoAddress_Click(object sender, RoutedEventArgs e) 
{ 
    ///Check if the URL or Address bar is blank 
    if(TxtWebAdd.Text != "") 
    { 
     Uri uriResult; 
     ///if not then checking if the URL is valid 
     if(Uri.TryCreate(TxtWebAdd.Text, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp) 
      wb1.Navigate(TxtWebAdd.Text); 
     else 
      MessageBox.Show("This is not a valid URL please check"); 
    } 
    else 
    { 
     ///this is how it will navigate to blank page when WebAddress TextBox is blank. 
     wb1.Navigate("about:blank"); 
    } 
} 
相關問題