RichTextBox.AutoWordSelection 属性

定义

获取或设置一个值,通过该值指示是否启用自动选择字词。

public:
 property bool AutoWordSelection { bool get(); void set(bool value); };
public bool AutoWordSelection { get; set; }
member this.AutoWordSelection : bool with get, set
Public Property AutoWordSelection As Boolean

属性值

Boolean

如果启用自动选择字词,则为 true;否则为 false。 默认值为 true

示例

下面的代码示例演示如何创建一个 RichTextBox 放大文本的函数,在双击某个单词时自动选择控件文本中的单词,并在控件的工作区右侧有边距。 RichTextBox如果控件的宽度较小,则使用此代码将创建RichTextBox文本的每个字符在其自己的行上显示的位置。 在此垂直显示位置中,单击单词的任何部分将选择单词的所有字符,而不考虑文本垂直显示的事实。 This example requires that you have a form that contains a RichTextBox control named richTextBox1.

private:
   void ZoomMyRichTextBox()
   {
      // Enable users to select entire word when double clicked.
      richTextBox1->AutoWordSelection = true;

      // Clear contents of control.
      richTextBox1->Clear();

      // Set the right margin to restrict horizontal text.
      richTextBox1->RightMargin = 2;

      // Set the text for the control.
      richTextBox1->SelectedText = "Alpha Bravo Charlie Delta Echo Foxtrot";

      // Zoom by 2 points.
      richTextBox1->ZoomFactor = 2.0f;
   }
private void ZoomMyRichTextBox()
{
    // Enable users to select entire word when double clicked.
    richTextBox1.AutoWordSelection = true;
    // Clear contents of control.
    richTextBox1.Clear();
    // Set the right margin to restrict horizontal text.
    richTextBox1.RightMargin = 2;
    // Set the text for the control.
    richTextBox1.SelectedText = "Alpha Bravo Charlie Delta Echo Foxtrot";
    // Zoom by 2 points.
    richTextBox1.ZoomFactor = 2.0f;
}
Private Sub ZoomMyRichTextBox()
    ' Enable users to select entire word when double clicked.
    richTextBox1.AutoWordSelection = True
    ' Clear contents of control.
    richTextBox1.Clear()
    ' Set the right margin to restrict horizontal text.
    richTextBox1.RightMargin = 2
    ' Set the text for the control.
    richTextBox1.SelectedText = "Alpha Bravo Charlie Delta Echo Foxtrot"
    ' Zoom by 2 points.
    richTextBox1.ZoomFactor = 2.0F
End Sub

注解

如果此属性设置为 true,则选择控件中文本的任何部分将选择整个单词。

适用于