TextBox.AutoCompleteCustomSource 属性


获取或设置一个自定义 StringCollection,以便在 AutoCompleteSource 属性被设置为 CustomSource 时使用。Gets or sets a custom StringCollection to use when the AutoCompleteSource property is set to CustomSource.

 property System::Windows::Forms::AutoCompleteStringCollection ^ AutoCompleteCustomSource { System::Windows::Forms::AutoCompleteStringCollection ^ get(); void set(System::Windows::Forms::AutoCompleteStringCollection ^ value); };
public System.Windows.Forms.AutoCompleteStringCollection AutoCompleteCustomSource { get; set; }
member this.AutoCompleteCustomSource : System.Windows.Forms.AutoCompleteStringCollection with get, set
Public Property AutoCompleteCustomSource As AutoCompleteStringCollection



一个与 AutoCompleteSource 一起使用的 StringCollectionA StringCollection to use with AutoCompleteSource.



下面的代码示例演示如何使用集合作为控件的自动完成自定义源 TextBoxThe following code example demonstrates how to use a collection as the auto-complete custom source for a TextBox control. 此示例将执行下列操作:This example does the following:

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[]

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

    // Add the text box to the form.
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.
End Sub


使用 AutoCompleteCustomSourceAutoCompleteModeAutoCompleteSource 属性创建一个 TextBox ,它通过将输入的前缀与维护的源中的所有字符串的前缀进行比较来自动完成输入字符串。Use the AutoCompleteCustomSource, AutoCompleteMode, and AutoCompleteSource properties to create a TextBox that automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source. 这对于 TextBox 经常输入 url、地址、文件名或命令的控件很有用。This is useful for TextBox controls in which URLs, addresses, file names, or commands will be frequently entered.

属性的使用 AutoCompleteCustomSource 是可选的,但必须将 AutoCompleteSource 属性设置为才能 CustomSource 使用 AutoCompleteCustomSourceThe use of the AutoCompleteCustomSource property is optional, but you must set the AutoCompleteSource property to CustomSource in order to use AutoCompleteCustomSource.

您必须同时使用 AutoCompleteModeAutoCompleteSource 属性。You must use the AutoCompleteMode and AutoCompleteSource properties together.


操作系统可能会限制它可以同时显示的自定义字符串的数目。The operating system might limit the number of custom strings that it can display at once.