Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:6k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace WebBrowser
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.TextBox textUrl;
- private AxSHDocVw.AxWebBrowser axWebBrowser1;
- private System.Windows.Forms.Button buttonNavigate;
- private System.Windows.Forms.Button buttonBack;
- private System.Windows.Forms.Button buttonForward;
- private System.Windows.Forms.StatusBar statusBar;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.panel1 = new System.Windows.Forms.Panel();
- this.buttonForward = new System.Windows.Forms.Button();
- this.buttonBack = new System.Windows.Forms.Button();
- this.buttonNavigate = new System.Windows.Forms.Button();
- this.textUrl = new System.Windows.Forms.TextBox();
- this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
- this.statusBar = new System.Windows.Forms.StatusBar();
- this.panel1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
- this.SuspendLayout();
- //
- // panel1
- //
- this.panel1.Controls.Add(this.buttonForward);
- this.panel1.Controls.Add(this.buttonBack);
- this.panel1.Controls.Add(this.buttonNavigate);
- this.panel1.Controls.Add(this.textUrl);
- this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.panel1.Location = new System.Drawing.Point(0, 0);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(512, 48);
- this.panel1.TabIndex = 0;
- //
- // buttonForward
- //
- this.buttonForward.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.buttonForward.Location = new System.Drawing.Point(376, 8);
- this.buttonForward.Name = "buttonForward";
- this.buttonForward.Size = new System.Drawing.Size(56, 23);
- this.buttonForward.TabIndex = 3;
- this.buttonForward.Text = "Forward";
- this.buttonForward.Click += new System.EventHandler(this.OnForward);
- //
- // buttonBack
- //
- this.buttonBack.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.buttonBack.Location = new System.Drawing.Point(320, 8);
- this.buttonBack.Name = "buttonBack";
- this.buttonBack.Size = new System.Drawing.Size(48, 23);
- this.buttonBack.TabIndex = 2;
- this.buttonBack.Text = "Back";
- this.buttonBack.Click += new System.EventHandler(this.OnBack);
- //
- // buttonNavigate
- //
- this.buttonNavigate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.buttonNavigate.Location = new System.Drawing.Point(240, 8);
- this.buttonNavigate.Name = "buttonNavigate";
- this.buttonNavigate.Size = new System.Drawing.Size(64, 23);
- this.buttonNavigate.TabIndex = 1;
- this.buttonNavigate.Text = "Navigate";
- this.buttonNavigate.Click += new System.EventHandler(this.OnNavigate);
- //
- // textUrl
- //
- this.textUrl.Location = new System.Drawing.Point(16, 8);
- this.textUrl.Name = "textUrl";
- this.textUrl.Size = new System.Drawing.Size(208, 20);
- this.textUrl.TabIndex = 0;
- this.textUrl.Text = "";
- //
- // axWebBrowser1
- //
- this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.axWebBrowser1.Enabled = true;
- this.axWebBrowser1.Location = new System.Drawing.Point(0, 48);
- this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
- this.axWebBrowser1.Size = new System.Drawing.Size(512, 261);
- this.axWebBrowser1.TabIndex = 1;
- this.axWebBrowser1.StatusTextChange += new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.OnStatusChange);
- this.axWebBrowser1.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
- //
- // statusBar
- //
- this.statusBar.Location = new System.Drawing.Point(0, 287);
- this.statusBar.Name = "statusBar";
- this.statusBar.Size = new System.Drawing.Size(512, 22);
- this.statusBar.TabIndex = 2;
- this.statusBar.Text = "statusBar";
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(512, 309);
- this.Controls.Add(this.statusBar);
- this.Controls.Add(this.axWebBrowser1);
- this.Controls.Add(this.panel1);
- this.Name = "Form1";
- this.Text = "Simple Browser";
- this.panel1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void OnNavigate(object sender, System.EventArgs e)
- {
- object noArg = null;
- this.axWebBrowser1.Navigate(textUrl.Text, ref noArg, ref noArg, ref noArg, ref noArg);
- }
- private void OnBack(object sender, System.EventArgs e)
- {
- try
- {
- this.axWebBrowser1.GoBack();
- }
- catch
- {
- }
- }
- private void OnForward(object sender, System.EventArgs e)
- {
- try
- {
- axWebBrowser1.GoForward();
- }
- catch
- {
- }
- }
- private void OnStatusChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
- {
- this.statusBar.Text = e.text;
- }
- private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
- {
- this.textUrl.Text = e.uRL.ToString();
- }
- }
- }