展开全部
动态加载ToolStrip上的ToolStripButton,其实是图标大小可选而已,自己可以如法自定义多种。
1. 使用大图标/小图标
追加的菜单事件中写控制ToolStrip的ImageScalingSize属性的代码:
/// <summary>
/// 大图标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiLargeIcon_Click(object sender, EventArgs e)
{
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);// 设置为32*32
this.toolStrip1.Height = 32;
foreach (ToolStripItem tsmi in this.toolStrip1.Items)
{
if (tsmi is ToolStripButton)
{
tsmi.AutoSize = false;
tsmi.Height = 32;
tsmi.Width = 32;
tsmi.AutoSize = true;
}
}
}
/// <summary>
/// 小图标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiSmallIcon_Click(object sender, EventArgs e)
{
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(16, 16);
this.toolStrip1.Height = 23;
foreach (ToolStripItem tsmi in this.toolStrip1.Items)
{
if (tsmi is ToolStripButton)
{
tsmi.AutoSize = false;
tsmi.Height = 16;
tsmi.Width = 16;
tsmi.AutoSize = true;
}
}
}
请注意:要在改变工具按钮前将【AutoSize】设为【false】,是因为只有设置此项,才能改变ToolStripButton的大小。
1. 使用大图标/小图标
追加的菜单事件中写控制ToolStrip的ImageScalingSize属性的代码:
/// <summary>
/// 大图标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiLargeIcon_Click(object sender, EventArgs e)
{
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);// 设置为32*32
this.toolStrip1.Height = 32;
foreach (ToolStripItem tsmi in this.toolStrip1.Items)
{
if (tsmi is ToolStripButton)
{
tsmi.AutoSize = false;
tsmi.Height = 32;
tsmi.Width = 32;
tsmi.AutoSize = true;
}
}
}
/// <summary>
/// 小图标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiSmallIcon_Click(object sender, EventArgs e)
{
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(16, 16);
this.toolStrip1.Height = 23;
foreach (ToolStripItem tsmi in this.toolStrip1.Items)
{
if (tsmi is ToolStripButton)
{
tsmi.AutoSize = false;
tsmi.Height = 16;
tsmi.Width = 16;
tsmi.AutoSize = true;
}
}
}
请注意:要在改变工具按钮前将【AutoSize】设为【false】,是因为只有设置此项,才能改变ToolStripButton的大小。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询