共用方式為


ToolStripItem.Alignment 屬性

定義

取得或設定一個值,指示該項目是否朝向 的開始或結尾 ToolStrip

public:
 property System::Windows::Forms::ToolStripItemAlignment Alignment { System::Windows::Forms::ToolStripItemAlignment get(); void set(System::Windows::Forms::ToolStripItemAlignment value); };
public System.Windows.Forms.ToolStripItemAlignment Alignment { get; set; }
member this.Alignment : System.Windows.Forms.ToolStripItemAlignment with get, set
Public Property Alignment As ToolStripItemAlignment

屬性值

這是其中一項 ToolStripItemAlignment 價值。 預設值為 Left

例外狀況

分配的值並非其中之一。ToolStripItemAlignment

範例

以下程式碼範例示範如何設定該 Alignment 屬性。 此程式碼範例是本類別更大範例 ToolStripItem 的一部分。

// This utility method creates a RolloverItem 
// and adds it to a ToolStrip control.
private RolloverItem CreateRolloverItem(
    ToolStrip owningToolStrip,
    string txt,
    Font f,
    string imgKey,
    TextImageRelation tir,
    string backImgKey)
{
    RolloverItem item = new RolloverItem();

    item.Alignment = ToolStripItemAlignment.Left;
    item.AllowDrop = false;
    item.AutoSize = true;

    item.BackgroundImage = owningToolStrip.ImageList.Images[backImgKey];
    item.BackgroundImageLayout = ImageLayout.Center;
    item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
    item.DoubleClickEnabled = true;
    item.Enabled = true;
    item.Font = f;

    // These assignments are equivalent. Each assigns an
    // image from the owning toolstrip's image list.
    item.ImageKey = imgKey;
    //item.Image = owningToolStrip.ImageList.Images[infoIconKey];
    //item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
    item.ImageScaling = ToolStripItemImageScaling.None;

    item.Owner = owningToolStrip;
    item.Padding = new Padding(2);
    item.Text = txt;
    item.TextAlign = ContentAlignment.MiddleLeft;
    item.TextDirection = ToolStripTextDirection.Horizontal;
    item.TextImageRelation = tir;

    return item;
}
' This utility method creates a RolloverItem 
' and adds it to a ToolStrip control.
 Private Function CreateRolloverItem( _
 ByVal owningToolStrip As ToolStrip, _
 ByVal txt As String, _
 ByVal f As Font, _
 ByVal imgKey As String, _
 ByVal tir As TextImageRelation, _
 ByVal backImgKey As String) As RolloverItem

     Dim item As New RolloverItem()

     item.Alignment = ToolStripItemAlignment.Left
     item.AllowDrop = False
     item.AutoSize = True

     item.BackgroundImage = owningToolStrip.ImageList.Images(backImgKey)
     item.BackgroundImageLayout = ImageLayout.Center
     item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
     item.DoubleClickEnabled = True
     item.Enabled = True
     item.Font = f

     ' These assignments are equivalent. Each assigns an
     ' image from the owning toolstrip's image list.
     item.ImageKey = imgKey
     'item.Image = owningToolStrip.ImageList.Images[infoIconKey];
     'item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
     item.ImageScaling = ToolStripItemImageScaling.None

     item.Owner = owningToolStrip
     item.Padding = New Padding(2)
     item.Text = txt
     item.TextAlign = ContentAlignment.MiddleLeft
     item.TextDirection = ToolStripTextDirection.Horizontal
     item.TextImageRelation = tir

     Return item
 End Function

備註

在堆疊溢位佈局中,使用屬性 Alignment 與屬性 ToolStripItem.RightToLeft 來控制項目在 中對齊 ToolStrip的端點,或判斷它們已對齊的端點。

ToolStripItem.RightToLeft 屬性為 No,標記為 Left 的項目對齊於左側 ToolStrip ,標記 Right 為的項目則對齊於右側。

ToolStripItem.RightToLeft 屬性為 Yes,標記為 Left 的項目對齊於右側 ToolStrip ,標記 Right 為的項目對齊於左側。

備註

在流程與表格佈局中,該 Alignment 屬性會被忽略。 在流程或表格配置中,使用 Dock or Anchor 屬性來對齊列或表格儲存格內的項目。

適用於