Form1.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:8k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace MyIEApp
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.StatusBar statusBar1;
- private AxSHDocVw.AxWebBrowser MyWebBrowser;
- private System.Windows.Forms.ComboBox MyAddressBox;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.ToolBarButton toolBarButton1;
- private System.Windows.Forms.ToolBarButton toolBarButton2;
- private System.Windows.Forms.ToolBarButton toolBarButton3;
- private System.Windows.Forms.ToolBarButton toolBarButton4;
- private System.Windows.Forms.ToolBarButton toolBarButton5;
- private System.Windows.Forms.ToolBarButton toolBarButton6;
- private System.Windows.Forms.ToolBar toolBar1;
- private System.ComponentModel.IContainer components;
- public Form1()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.statusBar1 = new System.Windows.Forms.StatusBar();
- this.MyWebBrowser = new AxSHDocVw.AxWebBrowser();
- this.MyAddressBox = new System.Windows.Forms.ComboBox();
- this.label1 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.Panel();
- this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
- this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
- this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
- this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
- this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
- this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
- this.toolBar1 = new System.Windows.Forms.ToolBar();
- ((System.ComponentModel.ISupportInitialize)(this.MyWebBrowser)).BeginInit();
- this.panel1.SuspendLayout();
- this.SuspendLayout();
- //
- // statusBar1
- //
- this.statusBar1.Location = new System.Drawing.Point(0, 333);
- this.statusBar1.Name = "statusBar1";
- this.statusBar1.Size = new System.Drawing.Size(496, 16);
- this.statusBar1.TabIndex = 4;
- //
- // MyWebBrowser
- //
- this.MyWebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
- this.MyWebBrowser.Enabled = true;
- this.MyWebBrowser.Location = new System.Drawing.Point(0, 0);
- this.MyWebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("MyWebBrowser.OcxState")));
- this.MyWebBrowser.Size = new System.Drawing.Size(496, 349);
- this.MyWebBrowser.TabIndex = 0;
- this.MyWebBrowser.StatusTextChange += new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.MyWebBrowser_StatusTextChange);
- //
- // MyAddressBox
- //
- this.MyAddressBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.MyAddressBox.ItemHeight = 12;
- this.MyAddressBox.Location = new System.Drawing.Point(56, 8);
- this.MyAddressBox.Name = "MyAddressBox";
- this.MyAddressBox.Size = new System.Drawing.Size(434, 20);
- this.MyAddressBox.TabIndex = 5;
- this.MyAddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MyAddressBox_KeyPress);
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(5, 13);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(48, 16);
- this.label1.TabIndex = 4;
- this.label1.Text = "地址:";
- //
- // panel1
- //
- this.panel1.Controls.Add(this.MyAddressBox);
- this.panel1.Controls.Add(this.label1);
- this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.panel1.Location = new System.Drawing.Point(0, 41);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(496, 40);
- this.panel1.TabIndex = 5;
- //
- // toolBarButton1
- //
- this.toolBarButton1.ImageIndex = 0;
- this.toolBarButton1.Text = "后退";
- //
- // toolBarButton2
- //
- this.toolBarButton2.ImageIndex = 1;
- this.toolBarButton2.Text = "前进";
- //
- // toolBarButton3
- //
- this.toolBarButton3.ImageIndex = 2;
- this.toolBarButton3.Text = "停止";
- //
- // toolBarButton4
- //
- this.toolBarButton4.ImageIndex = 3;
- this.toolBarButton4.Text = "刷新";
- //
- // toolBarButton5
- //
- this.toolBarButton5.ImageIndex = 4;
- this.toolBarButton5.Text = "主页";
- //
- // toolBarButton6
- //
- this.toolBarButton6.ImageIndex = 5;
- this.toolBarButton6.Text = "搜索";
- //
- // toolBar1
- //
- this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.toolBarButton1,
- this.toolBarButton2,
- this.toolBarButton3,
- this.toolBarButton4,
- this.toolBarButton5,
- this.toolBarButton6});
- this.toolBar1.ButtonSize = new System.Drawing.Size(49, 35);
- this.toolBar1.DropDownArrows = true;
- this.toolBar1.Font = new System.Drawing.Font("华文行楷", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
- this.toolBar1.Location = new System.Drawing.Point(0, 0);
- this.toolBar1.Name = "toolBar1";
- this.toolBar1.ShowToolTips = true;
- this.toolBar1.Size = new System.Drawing.Size(496, 41);
- this.toolBar1.TabIndex = 1;
- this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(496, 349);
- this.Controls.Add(this.panel1);
- this.Controls.Add(this.statusBar1);
- this.Controls.Add(this.toolBar1);
- this.Controls.Add(this.MyWebBrowser);
- this.Name = "Form1";
- this.Text = "模拟IE浏览器";
- ((System.ComponentModel.ISupportInitialize)(this.MyWebBrowser)).EndInit();
- this.panel1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- try
- {
- switch (toolBar1.Buttons.IndexOf (e.Button ))
- {
- case 0:
- MyWebBrowser.GoBack (); //后退
- break;
- case 1:
- MyWebBrowser.GoForward (); //前进
- break;
- case 2:
- MyWebBrowser.Stop (); //停止
- break;
- case 3:
- MyWebBrowser.Refresh (); //刷新
- break;
- case 4:
- MyWebBrowser.GoHome (); //主页
- break;
- case 5:
- MyWebBrowser.GoSearch (); //搜索
- break;
- }
- }
- catch{}
- }
- private void MyNavigate()
- {
- object anObject = new object ();
- try
- {
- this.MyWebBrowser.Navigate(MyAddressBox.Text , ref anObject, ref anObject, ref anObject, ref anObject);
- }
- catch{}
- AddAdress();
- statusBar1.Text = MyWebBrowser.LocationName ;
- }
- private void AddAdress()
- {
- int AdressIndex = MyAddressBox.FindStringExact (MyAddressBox.Text );
- if (AdressIndex < 0) //如果地址不在ComboBox中,则添加地址
- {
- MyAddressBox.Items.Add (MyAddressBox.Text);
- }
- }
- private void MyAddressBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
- {
- if ( e.KeyChar == (char)13 ) //回车
- {
- MyNavigate();
- e.Handled = true;
- }
- }
- private void MyWebBrowser_StatusTextChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
- {
- statusBar1.Text = e.text;
- }
- }
- }