在可能是VS的一个bug。
就是你给toolstrip添加了按钮,弄好了图标,修改了名称,结果还是一会出现这些按钮,一会又没了。
怎么办?
解决方法是在 *.Designer.cs 文件里面(就是本窗口的设计代码),找到:private void InitializeComponent() { } 方法。然后在里面在找到:// // toolStrip1 // this.toolStrip1.Dock = System.Windows.Forms.DockStyle.Fill; this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(284, 41); this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = "toolStrip1"; this.toolStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.toolStrip1_ItemClicked);
类似上面的代码。
然后在上面代码的最前面添加上如下代码:
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btnRectQuery,
this.toolStripButton1,
this.toolStripSeparator1,
this.toolStripDropDownButton1});
{}里面的部分就是你的图标的name。
如果你的toolstrip里面包含dropbuttondown这样的控件,图标也消失了,也可以按照同样的方法添加进去。
如果实在不知道代码怎么写,可以重新建一个项目或者窗体,添加一个toolstrip,看看正确的Designer.cs代码怎么写的。