当前位置: 首页>>代码示例>>C#>>正文


C# WebBrowser.GoHome方法代码示例

本文整理汇总了C#中System.Windows.Forms.WebBrowser.GoHome方法的典型用法代码示例。如果您正苦于以下问题:C# WebBrowser.GoHome方法的具体用法?C# WebBrowser.GoHome怎么用?C# WebBrowser.GoHome使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.WebBrowser的用法示例。


在下文中一共展示了WebBrowser.GoHome方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: homeButton_Click

// Navigates webBrowser1 to the home page of the current user.
private void homeButton_Click(object sender, EventArgs e)
{
    webBrowser1.GoHome();
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:5,代码来源:WebBrowser.GoHome

示例2: WebBrowser.GoHome()

//引入命名空间
using System;
using System.Windows.Forms;

public class SimpleWebBrowser : Form
{
    public SimpleWebBrowser()
    {
        InitializeComponent();
        webBrowser1.Navigate("http://www.java2s.com");
    }

    private void goButton_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate(textURL.Text);
    }

    private void homeButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoHome();
    }

    private void backButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoBack();
    }

    private void forwarButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoForward();
    }

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        textURL.Text = webBrowser1.Url.ToString();

        if (webBrowser1.CanGoBack)
        {
            backButton.Enabled = true;
        }
        else
        {
            backButton.Enabled = false;
        }

        if (webBrowser1.CanGoForward)
        {
            forwarButton.Enabled = true;
        }
        else
        {
            forwarButton.Enabled = false;
        }
    }

    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new SimpleWebBrowser());
    }
    private void InitializeComponent()
    {
        this.webBrowser1 = new System.Windows.Forms.WebBrowser();
        this.goButton = new System.Windows.Forms.Button();
        this.textURL = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.backButton = new System.Windows.Forms.Button();
        this.homeButton = new System.Windows.Forms.Button();
        this.forwarButton = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // webBrowser1
        // 
        this.webBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.webBrowser1.Location = new System.Drawing.Point(-2, 2);
        this.webBrowser1.Name = "webBrowser1";
        this.webBrowser1.Size = new System.Drawing.Size(685, 190);
        this.webBrowser1.TabIndex = 3;
        this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
        // 
        // goButton
        // 
        this.goButton.Location = new System.Drawing.Point(435, 216);
        this.goButton.Name = "goButton";
        this.goButton.Size = new System.Drawing.Size(48, 23);
        this.goButton.TabIndex = 1;
        this.goButton.Text = "Go";
        this.goButton.Click += new System.EventHandler(this.goButton_Click);
        // 
        // textURL
        // 
        this.textURL.Location = new System.Drawing.Point(240, 217);
        this.textURL.Name = "textURL";
        this.textURL.Size = new System.Drawing.Size(189, 20);
        this.textURL.TabIndex = 2;
        this.textURL.Text = "http://www.java2s.com";
        // 
        // label1
        // 
        this.label1.Location = new System.Drawing.Point(206, 221);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(31, 13);
        this.label1.TabIndex = 0;
        this.label1.Text = "Go to:";
        // 
        // backButton
        // 
        this.backButton.Enabled = false;
        this.backButton.Location = new System.Drawing.Point(227, 249);
        this.backButton.Name = "backButton";
        this.backButton.Size = new System.Drawing.Size(75, 23);
        this.backButton.TabIndex = 0;
        this.backButton.Text = "<< Back";
        this.backButton.Click += new System.EventHandler(this.backButton_Click);
        // 
        // homeButton
        // 
        this.homeButton.Location = new System.Drawing.Point(308, 249);
        this.homeButton.Name = "homeButton";
        this.homeButton.Size = new System.Drawing.Size(75, 23);
        this.homeButton.TabIndex = 0;
        this.homeButton.Text = "Home";
        this.homeButton.Click += new System.EventHandler(this.homeButton_Click);
        // 
        // forwarButton
        // 
        this.forwarButton.Enabled = false;
        this.forwarButton.Location = new System.Drawing.Point(389, 249);
        this.forwarButton.Name = "forwarButton";
        this.forwarButton.Size = new System.Drawing.Size(75, 23);
        this.forwarButton.TabIndex = 0;
        this.forwarButton.Text = "Forward >>";
        this.forwarButton.Click += new System.EventHandler(this.forwarButton_Click);
        // 
        // SimpleWebBrowser
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(684, 303);
        this.Controls.Add(this.forwarButton);
        this.Controls.Add(this.homeButton);
        this.Controls.Add(this.backButton);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.textURL);
        this.Controls.Add(this.goButton);
        this.Controls.Add(this.webBrowser1);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    private System.Windows.Forms.WebBrowser webBrowser1;
    private System.Windows.Forms.Button goButton;
    private System.Windows.Forms.TextBox textURL;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button backButton;
    private System.Windows.Forms.Button homeButton;
    private System.Windows.Forms.Button forwarButton;
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:159,代码来源:WebBrowser.GoHome


注:本文中的System.Windows.Forms.WebBrowser.GoHome方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。