Bagikan melalui


TextBox.AutoCompleteMode Properti

Definisi

Mendapatkan atau mengatur opsi yang mengontrol cara kerja penyelesaian otomatis untuk 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

Nilai Properti

Salah satu nilai AutoCompleteMode. Berikut ini adalah nilainya.

Append Menambahkan sisa string kandidat yang paling mungkin ke karakter yang ada, menyoroti karakter yang ditambahkan.

Suggest Menampilkan daftar drop-down tambahan yang terkait dengan kontrol edit. Drop-down ini diisi dengan satu atau beberapa string penyelesaian yang disarankan.

SuggestAppendMenambahkan opsi dan Append .Suggest

None Menonaktifkan penyelesaian otomatis. Ini adalah default.

Atribut

Pengecualian

Nilai yang ditentukan bukan salah satu nilai .AutoCompleteMode

Contoh

Contoh kode berikut menunjukkan cara menggunakan koleksi sebagai sumber kustom lengkapi otomatis untuk TextBox kontrol. Contoh ini melakukan hal berikut:

  • AutoCompleteSource Menggunakan properti untuk mengaktifkan TextBox kontrol untuk menerima sumber kustom untuk perilaku lengkapi otomatisnya.

  • AutoCompleteCustomSource Menggunakan properti untuk mengatur daftar nilai kustom.

  • AutoCompleteMode Menggunakan properti untuk mengatur bagaimana kandidat lengkapi otomatis ditampilkan.

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

Keterangan

AutoCompleteCustomSourceGunakan properti , AutoCompleteMode, dan AutoCompleteSource untuk membuat TextBox yang secara otomatis menyelesaikan string input dengan membandingkan awalan yang dimasukkan ke awalan semua string dalam sumber yang dipertahankan. Ini berguna untuk TextBox kontrol di mana URL, alamat, nama file, atau perintah akan sering dimasukkan.

Penggunaan AutoCompleteCustomSource properti bersifat opsional, tetapi Anda harus mengatur AutoCompleteSource properti ke CustomSource untuk menggunakan AutoCompleteCustomSource.

Anda harus menggunakan AutoCompleteMode properti dan AutoCompleteSource bersama-sama.

Nota

Sistem operasi mungkin membatasi jumlah string kustom yang dapat ditampilkan sekaligus.

Berlaku untuk

Lihat juga