ToolStripItem.Text Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur teks yang akan ditampilkan pada item.
public:
virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public virtual string Text { get; set; }
public virtual string? Text { get; set; }
member this.Text : string with get, set
Public Overridable Property Text As String
Nilai Properti
String yang mewakili teks item. Nilai default adalah string kosong ("").
Contoh
Contoh kode berikut menunjukkan cara mengatur Textproperti , , Overflowdan TextDirection , dan menangani Click peristiwa. Untuk menjalankan contoh ini, tempelkan kode berikut ke dalam formulir yang berisi ToolStrip nama movingToolStrip
dan panggilan InitializeMovingToolStrip
di konstruktor formulir atau Load
penanganan aktivitas.
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
Keterangan
Anda dapat membuat kunci akses ke item dengan menambahkan ampersand ("&") sebelum huruf dalam nilai teks. Untuk informasi selengkapnya, lihat Cara: Membuat Kunci Akses untuk Kontrol Formulir Windows.
ToolStripItem
Text menggunakan properti sebagai sumber default untuk ToolTip konten. Atur AutoToolTip ke untuk digunakan ToolTipText sebagai sumber untuk ToolTipfalse
konten.