ToolStripItem.Alignment 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出項目是否會向 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 的專案會對齊左邊。