TextBox.AutoCompleteSource Propiedad

Definición

Obtiene o establece un valor que especifica el origen de cadenas completas utilizadas para la finalización automática.Gets or sets a value specifying the source of complete strings used for automatic completion.

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

Valor de propiedad

Uno de los valores de AutoCompleteSource.One of the values of AutoCompleteSource. Las opciones son AllSystemSources, AllUrl, FileSystem, HistoryList, RecentlyUsedList, CustomSource y None.The options are AllSystemSources, AllUrl, FileSystem, HistoryList, RecentlyUsedList, CustomSource, and None. De manera predeterminada, es None.The default is None.

Atributos

Excepciones

El valor especificado no es ninguno de los valores de AutoCompleteSource.The specified value is not one of the values of AutoCompleteSource.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar una colección como el origen personalizado de Autocompletar para un TextBox control.The following code example demonstrates how to use a collection as the auto-complete custom source for a TextBox control. En el ejemplo, se realizan las tareas siguientes:This example does the following:

  • Utiliza la AutoCompleteSource propiedad para permitir que TextBox el control acepte un origen personalizado para su comportamiento de autocompletar.Uses the AutoCompleteSource property to enable the TextBox control to accept a custom source for its auto-complete behavior.

  • Utiliza la AutoCompleteCustomSource propiedad para establecer la lista personalizada de valores.Uses the AutoCompleteCustomSource property to set the custom list of values.

  • Utiliza la AutoCompleteMode propiedad para establecer el modo en que se muestran los candidatos para Autocompletar.Uses the AutoCompleteMode property to set how the auto-complete candidates are displayed.

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

Comentarios

Use las AutoCompleteCustomSourcepropiedades AutoCompleteMode, y AutoCompleteSource para crear un TextBox que complete automáticamente las cadenas de entrada comparando el prefijo que se escribe con los prefijos de todas las cadenas en un origen mantenido.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. Esto resulta útil para TextBox los controles en los que se escriben con frecuencia direcciones URL, direcciones, nombres de archivo o comandos.This is useful for TextBox controls in which URLs, addresses, file names, or commands will be frequently entered.

El uso de la AutoCompleteCustomSource propiedad es opcional, pero debe establecer la AutoCompleteSource propiedad en para CustomSource poder usar AutoCompleteCustomSource.The use of the AutoCompleteCustomSource property is optional, but you must set the AutoCompleteSource property to CustomSource in order to use AutoCompleteCustomSource.

Debe utilizar las AutoCompleteMode propiedades y AutoCompleteSource conjuntamente.You must use the AutoCompleteMode and AutoCompleteSource properties together.

Nota

AutoCompleteSourceno funciona en controles multilínea TextBox .AutoCompleteSource does not work on multiline TextBox controls.

Nota

El sistema operativo puede limitar el número de cadenas personalizadas que se pueden mostrar a la vez.The operating system might limit the number of custom strings that can be displayed at once.

Se aplica a

Consulte también: