在经过前面那么多的努力之后,我们终于有一个简单的IE Extension了,就是我们的IE Toolbar,在开发IE Toolbar的时候我们还需要注意几点,就是在继承BandObject之后,我们开发的控件要设置minisize,也就是最小值,如果不设置最小值的话,就算你开发了Toolbar或者任何其他的东西,都无法在IE中看到,这是一个值得注意的地方。
OK,在经历了万千的磨难之后我们终于可以写一个Hello World了,示例代码如下所示。
namespace IEToolbar
{
[Guid("588E57A3-E8F7-43e8-8C98-406FBF563E59")]
[BandObject("IEToolbar", BandObjectStyle.Horizontal |
BandObjectStyle.ExplorerToolbar, HelpText = "IE Test Toolbar")]
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public partial class Toolbar : BandObject
{
public Toolbar()
{
InitializeComponent();
}
{
}
{
MessageBox.Show("Hello world");
}
}
}
{
[Guid("588E57A3-E8F7-43e8-8C98-406FBF563E59")]
[BandObject("IEToolbar", BandObjectStyle.Horizontal |
BandObjectStyle.ExplorerToolbar, HelpText = "IE Test Toolbar")]
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public partial class Toolbar : BandObject
{
public Toolbar()
{
InitializeComponent();
}
private void Toolbar_Load(object sender, EventArgs e)
{
}
private void toolStripLabel1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello world");
}
}
}
上面代码我们写了一个Load方法和一个Click方法,在toolStrip里面我们只是加了一个Label,design.cs代码如下。如果你做的Toolbar不能显示的话,可以对比一下我的这个代码。
private void InitializeComponent()
{
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.Dock = System.Windows.Forms.DockStyle.Fill;
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripLabel1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(373, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripLabel1
//
this.toolStripLabel1.Name = "toolStripLabel1";
this.toolStripLabel1.Size = new System.Drawing.Size(49, 22);
this.toolStripLabel1.Text = "Click me!";
this.toolStripLabel1.Click += new System.EventHandler(this.toolStripLabel1_Click);
//
// Toolbar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.toolStrip1);
this.MinimumSize = new System.Drawing.Size(150, 24);
this.Name = "Toolbar";
this.Size = new System.Drawing.Size(373, 25);
this.Load += new System.EventHandler(this.Toolbar_Load);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
{
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.Dock = System.Windows.Forms.DockStyle.Fill;
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripLabel1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(373, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripLabel1
//
this.toolStripLabel1.Name = "toolStripLabel1";
this.toolStripLabel1.Size = new System.Drawing.Size(49, 22);
this.toolStripLabel1.Text = "Click me!";
this.toolStripLabel1.Click += new System.EventHandler(this.toolStripLabel1_Click);
//
// Toolbar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.toolStrip1);
this.MinimumSize = new System.Drawing.Size(150, 24);
this.Name = "Toolbar";
this.Size = new System.Drawing.Size(373, 25);
this.Load += new System.EventHandler(this.Toolbar_Load);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
上面的代码只是一个Designer,如果你的Toolbar不能运行的话,就需要对比一下我这个了,看看自己是否做了不正确的事情。OK,同样,代码还是给下载吧。

不错,一学就会,多谢楼主恭喜,以及坚持不懈的更新精神!
I like how you write.Are you interesting in a part time writer job?
Would you like to post a guest post on my blog?
Do you accept guest posts? I would love to write couple articles here.
[...] IE Extension with C# – 终于要Hello World了 [...]
Thank you !!!!!!
如何解决这个问题啊?
错误 1 无法注册程序集“D:\Users\Documents\Visual Studio 2010\Projects\IEToolBar\IEToolBar\bin\Debug\IEToolBar.dll”。类型“IEToolbar.IEToolbarInstaller”违反了继承安全性规则。派生类型必须与基类型的安全可访问性匹配或者比基类型的安全可访问性低。 IEToolBar
@ifbs
这个我就不知道了,貌似是最新的问题吧,我现在没弄了,所以不了解,是我的sample的话,也报错么?