TextBoxBase.SelectAll 方法

定義

選取文字方塊中的所有文字。

public:
 void SelectAll();
public void SelectAll ();
member this.SelectAll : unit -> unit
Public Sub SelectAll ()

範例

下列程式碼範例會使用 TextBox 衍生類別,判斷控制項中是否選取任何文字。 如果未選取任何文字,則會先呼叫 SelectAll 方法,再將控制項的內容複寫到 剪貼簿。 此範例要求 TextBox 已建立名為 的 textBox1

public:
   void CopyAllMyText()
   {
      // Determine if any text is selected in the TextBox control.
      if ( textBox1->SelectionLength == 0 )
      {
         // Select all text in the text box.
         textBox1->SelectAll();
      }

      // Copy the contents of the control to the Clipboard.
      textBox1->Copy();
   }
public void CopyAllMyText()
 {
    // Determine if any text is selected in the TextBox control.
    if(textBox1.SelectionLength == 0)
       // Select all text in the text box.
       textBox1.SelectAll();
    
    // Copy the contents of the control to the Clipboard.
    textBox1.Copy();
 }
Public Sub CopyAllMyText()
    ' Determine if any text is selected in the TextBox control.
    If textBox1.SelectionLength = 0 Then
        ' Select all text in the text box.
        textBox1.SelectAll()
    End If 
    ' Copy the contents of the control to the Clipboard.
    textBox1.Copy()
End Sub

備註

這個方法可讓您選取控制項內的所有文字。 您可以使用這個方法搭配 Cut 方法,這需要控制項中選取文字,才能剪下控制項的整個內容,並將其貼到剪貼 簿 中。

適用於