2011-09-14 8 views
1

でボタンのクリックでWebページを開きます私のために仕事.....は、私は以下のコードを試してみましたが、それはない</p> <p>....私は、フォーム(Winフォーム)のボタンをクリックすると、Webページ(グーグル)を表示するフォーム

public partial class Form1 : Form { 
    bool mHooked; 
    public Form1() { 
     InitializeComponent(); 
     webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; 
     webBrowser1.Navigate("http://www.google.com"); 
    } 

    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { 
     if (mHooked) return; 
     // Get the form 
     HtmlDocument doc = webBrowser1.Document; 
     HtmlElement form = doc.Forms["f"]; 
     // Get the "I'm feeling lucky" button 
     HtmlElement lucky = form.All["btnI"]; 
     lucky.Click += lucky_Click; 
     mHooked = true; 
    } 
    void lucky_Click(object sender, EventArgs e) { 
     this.Close(); 
    } 
} 

は、私はC#の

を使用してのWinFormsアプリケーションをしています。この上の任意の1 PLSのに役立つだろう.....事前に

多くのおかげで...

+0

105:ボタンでリンクを提供していません – 62071072SP

+0

なぜクリックイベントでURLを設定していませんか? – V4Vendetta

+0

@ V4Vendetta私はちょうど1つの上に試した方法を知りません... –

答えて

4

まず追加するには、フォームにボタンを追加し、Clickイベントハンドラでボタンのクリックしたときに、この

private void button1_Click(object sender, EventArgs e) 
{   
    //remove this from the constructor else it will be loaded along with the form 
    webBrowser1.Navigate("http://www.google.com"); 
} 
+0

多くのありがとう、その働きは今.. –

4
public partial class Form1 : Form 

{ 

    bool mHooked; 

    public Form1() 

    { 
     InitializeComponent(); 
     webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; 
     //webBrowser1.Navigate("http://www.google.com"); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     webBrowser1.Navigate("http://www.google.com"); 
    } 
    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    { 
     if (mHooked) return; 
     // Get the form 
     HtmlDocument doc = webBrowser1.Document; 
     HtmlElement form = doc.Forms["f"];  
     // Get the "I'm feeling lucky" button 
     HtmlElement lucky = form.All["btnI"]; 
     lucky.Click += button1_Click; 
     mHooked = true; 
    } 
} 
0

の操作を行います。

ProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/"); 
Process.Start(sInfo); 

(または)

System.Diagnostics.Process.StartProcessStartInfo sInfo = new ProcessStartInfo("http://mysite.com/"); 
Process.Start(sInfo); 

ウェブスクレイピング技術を使用して特定のウェブサイトからデータを抽出したり、あなたのwinform自体にWebサイトを作成してから、Webブラウザのコントロールを使って、ShaliniPavanやV4Vendettaが提供する答えをお試しください。

+1

少なくともコードを見て、彼はwebbrowserコントロールを持っています。そして、彼はそれを所望のウェブサイトにナビゲートしようとする。 – Aidiakapi

関連する問題

 関連する問題