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

您必須同時使用 AutoCompleteModeAutoCompleteSource 屬性。

注意

作業系統可能會限制一次可以顯示的自訂字串數目。

適用於

另請參閱