TextBox.AutoCompleteMode 属性

定义

获取或设置一个选项,该选项控制自动完成应用于 TextBox 的方式。

public:
 property System::Windows::Forms::AutoCompleteMode AutoCompleteMode { System::Windows::Forms::AutoCompleteMode get(); void set(System::Windows::Forms::AutoCompleteMode value); };
[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.AutoCompleteMode AutoCompleteMode { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.AutoCompleteMode : System.Windows.Forms.AutoCompleteMode with get, set
Public Property AutoCompleteMode As AutoCompleteMode

属性值

AutoCompleteMode

AutoCompleteMode 值之一。 以下为这些值。

Append
将最可能的候选字符串的其余部分追加到现有的字符,并突出显示追加的字符。

Suggest
显示与编辑控件关联的辅助下拉列表。 此下拉列表填充了一个或多个建议完成字符串。

SuggestAppend
追加 SuggestAppend 选项。

None
禁用自动完成 这是默认设置。

属性

例外

指定的值不是 AutoCompleteMode 值之一。

示例

下面的代码示例演示如何将集合用作控件的 TextBox 自动完成自定义源。 此示例将执行下列操作:

private void Form1_Load(object sender, EventArgs e)
{
    // Create the list to use as the custom source. 
    var source = new AutoCompleteStringCollection();
    source.AddRange(new string[]
                    {
                        "January",
                        "February",
                        "March",
                        "April",
                        "May",
                        "June",
                        "July",
                        "August",
                        "September",
                        "October",
                        "November",
                        "December"
                    });

    // Create and initialize the text box.
    var textBox = new TextBox
                  {
                      AutoCompleteCustomSource = source,
                      AutoCompleteMode = 
                          AutoCompleteMode.SuggestAppend,
                      AutoCompleteSource =
                          AutoCompleteSource.CustomSource,
                      Location = new Point(20, 20),
                      Width = ClientRectangle.Width - 40,
                      Visible = true
                  };

    // Add the text box to the form.
    Controls.Add(textBox);
}
Private Sub Form1_Load(ByVal sender As System.Object, _
                       ByVal e As System.EventArgs) Handles MyBase.Load

    ' Create the list to use as the custom source.
    Dim MySource As New AutoCompleteStringCollection()
    MySource.AddRange(New String() _
                        { _
                            "January", _
                            "February", _
                            "March", _
                            "April", _
                            "May", _
                            "June", _
                            "July", _
                            "August", _
                            "September", _
                            "October", _
                            "November", _
                            "December" _
                        })

    ' Create and initialize the text box.
    Dim MyTextBox As New TextBox()
    With MyTextBox
        .AutoCompleteCustomSource = MySource
        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
        .AutoCompleteSource = AutoCompleteSource.CustomSource
        .Location = New Point(20, 20)
        .Width = Me.ClientRectangle.Width - 40
        .Visible = True
    End With

    ' Add the text box to the form.
    Me.Controls.Add(MyTextBox)
End Sub

注解

AutoCompleteCustomSource使用和AutoCompleteModeAutoCompleteSource属性创建一个TextBox自动完成输入字符串,方法是将输入的前缀与维护源中所有字符串的前缀进行比较。 这对于经常输入 URL、地址、文件名或命令的控件非常有用 TextBox

属性的使用 AutoCompleteCustomSource 是可选的,但您必须将 AutoCompleteSource 属性设置为 CustomSource 要使用的 AutoCompleteCustomSource属性。

必须 AutoCompleteMode 结合使用和 AutoCompleteSource 属性。

备注

操作系统可能会限制可以同时显示的自定义字符串数。

适用于

另请参阅