我在追加的菜单事件中写控制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的大小。