TextBoxBase.SelectAll TextBoxBase.SelectAll TextBoxBase.SelectAll TextBoxBase.SelectAll Method

定义

选定文本框中的所有文本。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名为textBox1的。This 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.

适用于