TextBoxBase.SelectAll 方法

选定文本框中的所有文本。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub SelectAll
用法
Dim instance As TextBoxBase

instance.SelectAll
public void SelectAll ()
public:
void SelectAll ()
public void SelectAll ()
public function SelectAll ()

备注

此方法使您能够选择控件中的所有文本。可以将此方法与 Cut 方法一起使用;这需要在控件中选择文本,剪切该控件的全部内容,并将这些内容粘贴到“剪贴板”中。

示例

下面的代码示例使用派生类 TextBox 确定是否在控件中选定了任何文本。如果没有选定任何文本,则在将控件的内容复制到“剪贴板”之前要调用 SelectAll 方法。此示例要求已经创建一个名为 textBox1TextBox

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
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 void CopyAllMyText()
{
    // Determine if any text is selected in the TextBox control.
    if (textBox1.get_SelectionLength() == 0) {
        // Select all text in the text box.
        textBox1.SelectAll();
    }
    // Copy the contents of the control to the Clipboard.
    textBox1.Copy();
} //CopyAllMyText

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

TextBoxBase 类
TextBoxBase 成员
System.Windows.Forms 命名空间