動態控制ToolStrip上ToolStripButton的大小(包括圖示的大小)
我在追加的選單事件中寫控制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的大小。