ToolStripItem.Alignment ToolStripItem.Alignment ToolStripItem.Alignment ToolStripItem.Alignment Property

定義

項目が ToolStrip の先頭または末尾のいずれに合わせて配置されるかを示す値を取得または設定します。Gets or sets a value indicating whether the item aligns towards the beginning or end of the 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 値のいずれか 1 つ。One of the ToolStripItemAlignment values. 既定値は、Left です。The default is Left.

例外

Alignmentプロパティを設定する方法を次のコード例に示します。The following code example demonstrates how to set the Alignment property. このコード例は、 ToolStripItemクラスに対して提供される大規模な例の一部です。This code example is part of a larger example provided for the ToolStripItem class.

// 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項目がに配置される端を制御したり、既に配置されている端を決定したりします。In a stack overflow layout, use the Alignment property along with the ToolStripItem.RightToLeft property to control the end to which items are aligned in a ToolStrip, or to determine the end to which they are already aligned.

Right ToolStrip LeftプロパティがNoの場合、としてマークされている項目はの左側に揃えられ、マークされた項目は右揃えになります。 ToolStripItem.RightToLeftIf the ToolStripItem.RightToLeft property is No, items marked as Left are aligned to the left side of the ToolStrip and items marked Right are aligned to the right.

Right ToolStrip LeftプロパティがYesの場合、としてマークされている項目はの右側に揃えられ、マークされた項目は左揃えになります。 ToolStripItem.RightToLeftIf the ToolStripItem.RightToLeft property is Yes, items marked as Left are aligned to the right side of the ToolStrip and items marked Right are aligned to the left.

注意

フローレイアウトとテーブルレイアウトではAlignment 、プロパティは無視されます。In flow and table layouts, the Alignment property is ignored. フローまたはテーブルレイアウトでDockは、プロパティまたはAnchorプロパティを使用して、行またはテーブルセル内のアイテムを整列します。In flow or table layout, use the Dock or Anchor property to align the items within the row or table cell.

適用対象