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

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 将忽略该属性。 在流或表格布局中,使用 DockAnchor 属性对齐行或表格单元格中的项。

适用于