' AUTOCOMPLETAR COMBOBOX --- 15 de mayo de 2003
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents comboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents btCerrar As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtEntrada As System.Windows.Forms.TextBox
Friend WithEvents txtPalabra As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.comboBox1 = New System.Windows.Forms.ComboBox
Me.btCerrar = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtEntrada = New System.Windows.Forms.TextBox
Me.txtPalabra = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'comboBox1
'
Me.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboBox1.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.comboBox1.Items.AddRange(New Object() {"accesibilidad privada (variables)", "accesibilidad protegida (variables)", "accesibilidad publica (variables)", "acoplar controles en formularios", "ADO (objetos de datos ActiveX)", "ADO.NET (acceso a datos desconectados)", "agregar controles a formularios", "alcance de un procedimiento", "aplicaciones distribuidas", "archivos binarios", "argumentos de un procedimiento", "array", "ASP.NET (paginas activas de servidor)", "autosize (propiedad)", "base de datos", "BASIC", "biblioteca de clases", "binarysearch (metodo de la clase Array)", "botones de formulario", "bucles condicionales (Do Loop)", "bucles de contador (For Next)", "bucles de enumeracion (For Each)", "buscar cadenas", "button (control)", "byte", "cache", "cadenas", "Case Else (instruccion)", "casilla de verificacion", "clases", "CLS (especificación de lenguaje comun)", "codigo", "ComboBox (control)", "comentarios en el codigo", "Concat (metodo de la clase String)", "controlador de evento", "conversión explicita", "conversión implicita"})
Me.comboBox1.Location = New System.Drawing.Point(16, 32)
Me.comboBox1.MaxDropDownItems = 15
Me.comboBox1.Name = "comboBox1"
Me.comboBox1.Size = New System.Drawing.Size(344, 24)
Me.comboBox1.TabIndex = 3
Me.comboBox1.TabStop = False
Me.comboBox1.Visible = False
'
'btCerrar
'
Me.btCerrar.BackColor = System.Drawing.SystemColors.Control
Me.btCerrar.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btCerrar.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btCerrar.ForeColor = System.Drawing.SystemColors.ControlText
Me.btCerrar.Location = New System.Drawing.Point(128, 168)
Me.btCerrar.Name = "btCerrar"
Me.btCerrar.Size = New System.Drawing.Size(96, 24)
Me.btCerrar.TabIndex = 1
Me.btCerrar.Text = "Cerrar"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.txtEntrada)
Me.GroupBox1.Controls.Add(Me.txtPalabra)
Me.GroupBox1.Controls.Add(Me.btCerrar)
Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.GroupBox1.Location = New System.Drawing.Point(8, 88)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(360, 208)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.BackColor = System.Drawing.SystemColors.Control
Me.Label3.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Label3.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(112, 24)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(142, 17)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Caracteres tecleados:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.BackColor = System.Drawing.SystemColors.Control
Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Label2.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(120, 96)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(121, 17)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Palabras elegidas:"
'
'txtEntrada
'
Me.txtEntrada.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtEntrada.Location = New System.Drawing.Point(8, 56)
Me.txtEntrada.Name = "txtEntrada"
Me.txtEntrada.Size = New System.Drawing.Size(344, 23)
Me.txtEntrada.TabIndex = 0
Me.txtEntrada.Text = ""
'
'txtPalabra
'
Me.txtPalabra.BackColor = System.Drawing.Color.White
Me.txtPalabra.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtPalabra.Location = New System.Drawing.Point(8, 128)
Me.txtPalabra.Name = "txtPalabra"
Me.txtPalabra.ReadOnly = True
Me.txtPalabra.Size = New System.Drawing.Size(344, 23)
Me.txtPalabra.TabIndex = 4
Me.txtPalabra.TabStop = False
Me.txtPalabra.Text = ""
Me.txtPalabra.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Label1.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(360, 72)
Me.Label1.TabIndex = 1
Me.Label1.Text = " Escribe una palabra de la lista de la derecha (letra inicial: a, b o c). Al come" & _
"nzar a escribir, se seleccionará la primera entrada de un cuadro combinado que c" & _
"oincida con lo escrito, y aparecerá en mayúsculas. ESC vacía la caja de texto."
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'RichTextBox1
'
Me.RichTextBox1.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RichTextBox1.Location = New System.Drawing.Point(376, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.ReadOnly = True
Me.RichTextBox1.Size = New System.Drawing.Size(264, 288)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.TabStop = False
Me.RichTextBox1.Text = "accesibilidad privada (variables)" & Microsoft.VisualBasic.ChrW(10) & "accesibilidad protegida (variables)" & Microsoft.VisualBasic.ChrW(10) & "accesibilid" & _
"ad publica (variables)" & Microsoft.VisualBasic.ChrW(10) & "acoplar controles en formularios" & Microsoft.VisualBasic.ChrW(10) & "ADO (objetos de datos Ac" & _
"tiveX)" & Microsoft.VisualBasic.ChrW(10) & "ADO.NET (acceso a datos desconectados)" & Microsoft.VisualBasic.ChrW(10) & "agregar controles a formularios" & Microsoft.VisualBasic.ChrW(10) & "al" & _
"cance de un procedimiento" & Microsoft.VisualBasic.ChrW(10) & "aplicaciones distribuidas" & Microsoft.VisualBasic.ChrW(10) & "archivos binarios" & Microsoft.VisualBasic.ChrW(10) & "argumentos" & _
" de un procedimiento" & Microsoft.VisualBasic.ChrW(10) & "array" & Microsoft.VisualBasic.ChrW(10) & "ASP.NET (paginas activas de servidor)" & Microsoft.VisualBasic.ChrW(10) & "autosize (propi" & _
"edad)" & Microsoft.VisualBasic.ChrW(10) & "base de datos" & Microsoft.VisualBasic.ChrW(10) & "BASIC" & Microsoft.VisualBasic.ChrW(10) & "biblioteca de clases" & Microsoft.VisualBasic.ChrW(10) & "binarysearch (metodo de la clase " & _
"Array)" & Microsoft.VisualBasic.ChrW(10) & "botones de formulario" & Microsoft.VisualBasic.ChrW(10) & "bucles condicionales (Do Loop)" & Microsoft.VisualBasic.ChrW(10) & "bucles de contador (" & _
"For Next)" & Microsoft.VisualBasic.ChrW(10) & "bucles de enumeracion (For Each)" & Microsoft.VisualBasic.ChrW(10) & "buscar cadenas" & Microsoft.VisualBasic.ChrW(10) & "button (control)" & Microsoft.VisualBasic.ChrW(10) & "byte" & Microsoft.VisualBasic.ChrW(10) & _
"cache" & Microsoft.VisualBasic.ChrW(10) & "cadenas" & Microsoft.VisualBasic.ChrW(10) & "Case Else (instruccion)" & Microsoft.VisualBasic.ChrW(10) & "casilla de verificacion" & Microsoft.VisualBasic.ChrW(10) & "clases" & Microsoft.VisualBasic.ChrW(10) & "CLS (especi" & _
"ficación de lenguaje comun)" & Microsoft.VisualBasic.ChrW(10) & "codigo" & Microsoft.VisualBasic.ChrW(10) & "ComboBox (control)" & Microsoft.VisualBasic.ChrW(10) & "comentarios en el codigo" & Microsoft.VisualBasic.ChrW(10) & "C" & _
"oncat (metodo de la clase String)" & Microsoft.VisualBasic.ChrW(10) & "controlador de evento" & Microsoft.VisualBasic.ChrW(10) & "conversión explicita" & Microsoft.VisualBasic.ChrW(10) & "con" & _
"versión implicita"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(642, 308)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.RichTextBox1)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.comboBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "ComboBox - Autocompletar"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
' Si cambio el texto del cuadro de texto txtEntrada
Private Sub txtEntrada_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEntrada.TextChanged
Dim cadena As String ' almacena los caracteres tecleados
Dim indice As Integer ' para buscar la cadena en la lista de elementos
cadena = txtEntrada.Text.ToLower ' cadena almacena los caracteres tecleados (en minùsculas)
indice = comboBox1.FindString(cadena) ' indice referido al ítem que contiene la cadena
' Si hay alguna coincidencia selecciono el elemento en la lista
' En listas y cuadros combinados, SelectedIndex -1 significa ningún ítem seleccionado
If indice > -1 Then
comboBox1.SelectedIndex = indice ' índice del elemento seleccionado
txtPalabra.Text = comboBox1.Text.ToUpper ' muestro la palabra elegida en mayúsculas
ElseIf indice = -1 Then
comboBox1.SelectedIndex = -1 ' para no elegir ningún elemento
End If
If txtEntrada.Text = "" Then ' si vacío la caja de texto
comboBox1.SelectedIndex = -1 ' para no elegir ningún elemento
txtPalabra.Text = ""
End If
End Sub
' Para detectar pulsaciones de teclas con el foco en el cuadro de texto txtEntrada
Private Sub txtEntrada_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEntrada.KeyUp
If e.KeyCode = Keys.Escape Then ' si pulso ESC vacío la caja de entrada de texto
txtEntrada.Text = ""
comboBox1.SelectedIndex = -1 ' para no elegir ningún elemento
txtPalabra.Text = ""
End If
End Sub
Private Sub btCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCerrar.Click
Close() ' salir del programa
End Sub
End Class