TextBoxBase.SelectAll 方法

定義

選取文字方塊中的所有文字。Selects all text in the text box.

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

範例

下列程式碼範例 TextBox 會使用衍生類別,來判斷控制項中是否已選取任何文字。The following code example uses TextBox, a derived class, to determine if any text is selected in the control. 如果未選取任何文字,則會在將 SelectAll 控制項的內容複寫到 剪貼 簿之前,對方法進行呼叫。If no text is selected, a call is made to the SelectAll method before copying the contents of the control to the Clipboard. 此範例需要 TextBox 建立名為的 textBox1This example requires that a TextBox has been created named 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

備註

這個方法可讓您選取控制項內的所有文字。This method enables you to select all text within the control. 您可以使用這個方法搭配 Cut 方法(需要在控制項中選取文字)來剪下控制項的整個內容,並將其貼到 剪貼 簿中。You can use this method in conjunction with the Cut method, which requires text to be selected in the control, to cut the entire contents of the control and paste them into the Clipboard.

適用於