由于是初学用这个控件,所以有些问题比较白痴,希望大家能谅解!:)
是否这个控件只是用来显示一个网页的内容,而本身不提供那些前进,后退,地址栏之类的按钮?
还是这些事件都必须自己在上面加许多BUTTON,然后用这些BUTTON来触发这些事件呢?还有,如果想在一个WINFORM程序中应用,怎么来控制它的最大最小化呢?如果谁有这方面的源码,麻烦帖一下吧,多谢!
是否这个控件只是用来显示一个网页的内容,而本身不提供那些前进,后退,地址栏之类的按钮?
还是这些事件都必须自己在上面加许多BUTTON,然后用这些BUTTON来触发这些事件呢?还有,如果想在一个WINFORM程序中应用,怎么来控制它的最大最小化呢?如果谁有这方面的源码,麻烦帖一下吧,多谢!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace MyProject
{
/// <summary>
/// fr_myie 的摘要说明。
/// </summary>
public class fr_myie : System.Windows.Forms.Form
{
private DevComponents.DotNetBar.PanelEx panelEx1;
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ToolBar toolBar1;
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.StatusBar statusBar1;
private DevExpress.XtraEditors.SimpleButton simpleButton1;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components; public fr_myie()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(fr_myie));
this.panelEx1 = new DevComponents.DotNetBar.PanelEx();
this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.toolBar1 = new System.Windows.Forms.ToolBar();
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.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.panelEx1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
this.SuspendLayout();
//
// panelEx1
//
this.panelEx1.Controls.Add(this.simpleButton1);
this.panelEx1.Controls.Add(this.statusBar1);
this.panelEx1.Controls.Add(this.toolBar1);
this.panelEx1.Controls.Add(this.comboBox1);
this.panelEx1.Controls.Add(this.label1);
this.panelEx1.Controls.Add(this.axWebBrowser1);
this.panelEx1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelEx1.Location = new System.Drawing.Point(0, 0);
this.panelEx1.Name = "panelEx1";
this.panelEx1.Size = new System.Drawing.Size(608, 437);
this.panelEx1.Style.Alignment = System.Drawing.StringAlignment.Center;
this.panelEx1.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;
this.panelEx1.Style.BackColor2.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2;
this.panelEx1.Style.BackgroundImagePosition = DevComponents.DotNetBar.eBackgroundImagePosition.Tile;
this.panelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText;
this.panelEx1.Style.GradientAngle = 90;
this.panelEx1.TabIndex = 1;
//
// simpleButton1
//
this.simpleButton1.Location = new System.Drawing.Point(520, 48);
this.simpleButton1.Name = "simpleButton1";
this.simpleButton1.Size = new System.Drawing.Size(75, 24);
this.simpleButton1.TabIndex = 5;
this.simpleButton1.Text = "转 到";
this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 415);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(608, 22);
this.statusBar1.TabIndex = 4;
//
// toolBar1
//
this.toolBar1.BackColor = System.Drawing.SystemColors.Control;
this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5,
this.toolBarButton6});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(608, 42);
this.toolBar1.TabIndex = 3;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// 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 = "搜索";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(48, 48);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(472, 20);
this.comboBox1.TabIndex = 2;
this.comboBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox1_KeyPress);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(8, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 1;
this.label1.Text = "地址:";
//
// axWebBrowser1
//
this.axWebBrowser1.BackColor = System.Drawing.SystemColors.Control;
this.axWebBrowser1.ContainingControl = this;
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new System.Drawing.Point(0, 80);
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(608, 328);
this.axWebBrowser1.TabIndex = 0;
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// fr_myie
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(608, 437);
this.Controls.Add(this.panelEx1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "fr_myie";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "我的浏览器";
this.Load += new System.EventHandler(this.fr_myie_Load);
this.panelEx1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
this.ResumeLayout(false); }
#endregion private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
this.axWebBrowser1.GoBack();
break;
case 1:
this.axWebBrowser1.GoForward();
break;
case 2:
this.axWebBrowser1.Stop();
break;
case 3:
this.axWebBrowser1.Refresh();
break;
case 4:
this.axWebBrowser1.GoHome();
break;
case 5:
this.axWebBrowser1.GoSearch();
break;
}
}
catch
{
} } private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
MyNaviate();
}
}
private void MyNaviate()
{
object anObject=new object();
try
{
this.axWebBrowser1.Navigate(this.comboBox1.Text,ref anObject,ref anObject,ref anObject,ref anObject);
}
catch
{
}
AddAdress();
this.statusBar1.Text=this.axWebBrowser1.LocationName;
}
private void AddAdress()
{
int AddressIndex=this.comboBox1.FindStringExact(this.comboBox1.Text);
if(AddressIndex<0)
{
this.comboBox1.Items.Add(this.comboBox1.Text);
}
} private void fr_myie_Load(object sender, System.EventArgs e)
{
} private void simpleButton1_Click(object sender, System.EventArgs e)
{
MyNaviate();
}
}
}