刚好做过这样的东西。给你点提示:
你可以公开ToolBal中的每个toolbarbutton,这样引用时就可以控制它所有的属性。公开的方法就看你的设计了,你可以为你的16的toolbarbutton设计16个属性,也可以用其他高级一点方法。
你可以公开ToolBal中的每个toolbarbutton,这样引用时就可以控制它所有的属性。公开的方法就看你的设计了,你可以为你的16的toolbarbutton设计16个属性,也可以用其他高级一点方法。
能具体点吗?谢谢
public class ToolBarWithButtons : System.Windows.Forms.ToolBar
{
public ToolBarWithButtons()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int ButtonCount
{
get
{
return this.Buttons.Count;
}
set
{
if (this.Buttons.Count > value)
{
while (this.Buttons.Count > value)
{
this.Buttons.RemoveAt(this.Buttons.Count-1);
}
}
else
{
while (this.Buttons.Count < value)
{
this.Buttons.Add("NewButtonText");
}
}
}
}
}
这样只能按顺序移出,不太方便
能不能将自定义控件的一个属性设成自动产生到InitializeComponent函数中的代码?
{
get{return toolBar.Buttons[0];}
set{toolBar.Buttons[0]=value;}
}这样在设计环境中就可以控制第一个toolbarbutton了。