动态创建Layout

public Form1()
{
InitializeComponent();
AddLayoutItems1(); //初始化
}
/// <summary>
/// 1、一个方法(定义一个枚举在其中获取枚举类型)
/// 2、遍历枚举值(工具条按钮条目中有text、Tag)、在条目中添加工具条按钮条目,点击这些条目触发一个事件
/// 3、在布局方法中()(sender 是作为工具条条目的).值
/// </summary>
private void AddLayoutItems1()
{
Array enums= Enum.GetValues(typeof(MdiLayout));
foreach (object item in enums)
{
ToolStripMenuItem newitem = new ToolStripMenuItem()
{
Text=item.ToString(),
Tag=item
};
newitem.Click += newitem_Click;
自动排列ToolStripMenuItem.DropDownItems.Add(newitem );
}

}

void newitem_Click(object sender, EventArgs e)
{
//ToolStripItem tool = sender as ToolStripItem;
//MdiLayout layout = (MdiLayout)tool.Tag;
this.LayoutMdi((MdiLayout)(sender as ToolStripItem).Tag);
}

转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
原文地址:https://www.cnblogs.com/laopo/p/4605025.html