TextBox.AutoCompleteSource 屬性


取得或設定值,以指定用於自動完成的完整字串來源。Gets or sets a value specifying the source of complete strings used for automatic completion.

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


AutoCompleteSource 的其中一個值。One of the values of AutoCompleteSource. 這些選項包括 AllSystemSourcesAllUrlFileSystemHistoryListRecentlyUsedListCustomSourceNoneThe options are AllSystemSources, AllUrl, FileSystem, HistoryList, RecentlyUsedList, CustomSource, and None. 預設為 NoneThe default is None.



指定值不是 AutoCompleteSource 的其中一個值。The specified value is not one of the values of AutoCompleteSource.


下列程式碼範例示範如何使用集合做為 TextBox 控制項的自動完成自訂來源。The 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


使用 [AutoCompleteCustomSource]、[AutoCompleteMode] 和 [AutoCompleteSource 屬性] 來建立 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. 這適用于通常會輸入 Url、位址、檔案名或命令的 TextBox 控制項。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.


AutoCompleteSource 無法在多行 TextBox 控制項上運作。AutoCompleteSource does not work on multiline TextBox controls.


作業系統可能會限制一次可以顯示的自訂字串數目。The operating system might limit the number of custom strings that can be displayed at once.