實現動態控制ToolStrip上ToolStripButton的大小

來源:互聯網
上載者:User

標籤:

一 設定固定大小的ToolStripButton

設定固定大小的ToolStripButton很簡單,ToolStripButton-->AutoSize屬性設定為false,size調整為自己想要的大小即可。

同時配合的是ToolStripButton所在的ToolStrip的屬性設定,最關鍵的是ImageScalingSize 屬性的設定:

this.toolStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);   //設定表徵圖的大小為32 * 32 像素,當然,可以設定為自己需要的大小

二 實現動態控制ToolStrip上ToolStripButton的大小動態載入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的大小。

實現動態控制ToolStrip上ToolStripButton的大小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.