ToolStripItem.Text ToolStripItem.Text ToolStripItem.Text ToolStripItem.Text Property

定義

項目に表示されるテキストを取得または設定します。Gets or sets the text that is to be displayed on the item.

public:
 virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public virtual string Text { get; set; }
member this.Text : string with get, set
Public Overridable Property Text As String

プロパティ値

項目のテキストを表す文字列。A string representing the item's text. 既定値は空の文字列 ("") です。The default value is the empty string ("").

次のコード例はText、、 Overflow、およびTextDirectionの各プロパティを設定し、 Clickイベントを処理する方法を示しています。The following code example demonstrates how to set the Text, Overflow, and TextDirection properties, and handle the Click event. この例を実行するにはToolStrip 、という名前movingToolStripのを含むフォームに次のコードを貼り付け、フォームLoadのコンストラクターまたはイベントハンドラーにを呼び出しInitializeMovingToolStripます。To run this example, paste the following code into a form that contains a ToolStrip named movingToolStrip and call InitializeMovingToolStrip in the form's constructor or Load event handler.

ToolStripButton^ changeDirectionButton;

void InitializeMovingToolStrip()
{
    changeDirectionButton = gcnew ToolStripButton;
    movingToolStrip->AutoSize = true;
    movingToolStrip->RenderMode = ToolStripRenderMode::System;
    changeDirectionButton->TextDirection = 
        ToolStripTextDirection::Vertical270;
    changeDirectionButton->Overflow = 
        ToolStripItemOverflow::Never;
    changeDirectionButton->Text = "Change Alignment";
    movingToolStrip->Items->Add(changeDirectionButton);
    changeDirectionButton->Click += gcnew EventHandler(this, 
        &Form1::changeDirectionButtonClick);
}

void changeDirectionButtonClick(Object^ sender, EventArgs^ e)
{
    ToolStripItem^ item = (ToolStripItem^) sender;
    if ((item->TextDirection == ToolStripTextDirection::Vertical270) 
        || (item->TextDirection == ToolStripTextDirection::Vertical90))
    {
        item->TextDirection = ToolStripTextDirection::Horizontal;
        movingToolStrip->Raft = RaftingSides::Top;
    }
    else
    {
        item->TextDirection = 
            ToolStripTextDirection::Vertical270;
        movingToolStrip->Raft = RaftingSides::Left;
    }
}


internal ToolStripButton changeDirectionButton;

private void InitializeMovingToolStrip()
{
          movingToolStrip = new ToolStrip();

	changeDirectionButton = new ToolStripButton();

	movingToolStrip.AutoSize = true;
	movingToolStrip.RenderMode = ToolStripRenderMode.System;

	changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270;
	changeDirectionButton.Overflow = ToolStripItemOverflow.Never;
	changeDirectionButton.Text = "Change Alignment";
		movingToolStrip.Items.Add(changeDirectionButton);
}


private void changeDirectionButton_Click(object sender, EventArgs e)
{

	ToolStripItem item = (ToolStripItem)sender;

	if (item.TextDirection == ToolStripTextDirection.Vertical270 || item.TextDirection == ToolStripTextDirection.Vertical90)
	{
		item.TextDirection = ToolStripTextDirection.Horizontal;
		movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top;
	}
	else
	{
		item.TextDirection = ToolStripTextDirection.Vertical270;
		movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left;
	}

}
Friend WithEvents changeDirectionButton As ToolStripButton

Private Sub InitializeMovingToolStrip()
    changeDirectionButton = New ToolStripButton()

    movingToolStrip.AutoSize = True
    movingToolStrip.RenderMode = ToolStripRenderMode.System

    changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270
    changeDirectionButton.Overflow = ToolStripItemOverflow.Never
    changeDirectionButton.Text = "Change Alignment"
    movingToolStrip.Items.Add(changeDirectionButton)
End Sub


Public Sub changeDirectionButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles changeDirectionButton.Click

    Dim item As ToolStripItem = CType(sender, ToolStripItem)

    If item.TextDirection = ToolStripTextDirection.Vertical270 _
        OrElse item.TextDirection = ToolStripTextDirection.Vertical90 Then

        item.TextDirection = ToolStripTextDirection.Horizontal
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top
    Else
        item.TextDirection = ToolStripTextDirection.Vertical270
        movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left
    End If

End Sub

注釈

テキスト値の文字の前にアンパサンド ("&") を追加することによって、項目へのアクセスキーを作成できます。You can create an access key to the item by adding an ampersand ("&") before a letter in the text value. 詳細については、「方法 :Windows フォームコントロールのアクセスキーを作成します。For more information, see How to: Create Access Keys for Windows Forms Controls.

ToolStripItemは、 Text ToolTipコンテンツの既定のソースとしてプロパティを使用します。ToolStripItem uses the Text property as the default source for the ToolTip content. コンテンツAutoToolTipfalse ToolTipTextソースとしてを使用するには、をに設定します。ToolTipSet AutoToolTip to false to use ToolTipText as the source for ToolTip content.

適用対象