Validaciones En Basic

Páginas: 70 (17252 palabras) Publicado: 12 de marzo de 2013
01 - Ejemplos varios para trabajar con controles textbox en visual basic.net
Solo números
Cambiar el foco a otro textbox al presionar enter
Seleccionar todo el texto
Evitar el beep al presionar enter
Mayúsculas y minúsculas
Guardar el texto de un textbox en un archivo txt
Leer líneas de un archivo de texto
Leer todo el contenido de un archivo de una sola vez
Limpiar todos los textboxdel formulario
 1 - Textbox que admite solo letras
Código fuente en un form con un textbox1
1. Private Sub TextBox1_KeyPress(ByVal sender As Object, _   
2.                           ByVal e As System.Windows.Forms.KeyPressEventArgs) _   
3.                               Handles TextBox1.KeyPress   
4.   
5.     If Char.IsLetter(e.KeyChar) Then  
6.        e.Handled = False  
7.     ElseIf Char.IsControl(e.KeyChar) Then  
8.         e.Handled = False  
9.     ElseIf Char.IsSeparator(e.KeyChar) Then  
10.         e.Handled = False  
11.     Else  
12.         e.Handled = True  
13.     End If  
14. End Sub   
Textbox que admite solo números o caracteres que quiera: (Esta es una forma que descubrí guiándome del código de vb6, y está biencortito).
Código fuente en el formulario con un textbox1
1. Private Sub TextBox1_KeyPress(ByVal sender As Object, _   
2.                               ByVal e As System.Windows.Forms.KeyPressEventArgs) _   
3.                               Handles TextBox1.KeyPress   
4.     If InStr(1, "0123456789,-" & Chr(8), e.KeyChar) = 0 Then  
5.         e.KeyChar = ""  
6.     End If  7. End Sub    
 Enlace relacionado: Ingresar solo números en DatagridView  
 2 - Cambiar el foco al otro textbox al presionar tab
Colocar varios varios controles textbox y el siguiente código
1. Private Sub TextBox1_KeyPress(ByVal sender As Object, _   
2.                           ByVal e As System.Windows.Forms.KeyPressEventArgs) _   
3.                              Handles TextBox1.KeyPress   
4.     If e.KeyChar = ChrW(Keys.Enter) Then  
5.         e.Handled = True  
6.         SendKeys.Send("{TAB}")   
7.     End If  
8. End Sub  
 3 - Seleccionar todo el texto del control al recibir el foco con el método SelectAll 
1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _   
2.                                   ByVal e As System.EventArgs) _   
3.                                  Handles TextBox1.TextChanged   
4.     TextBox1.SelectAll()   
5. End Sub  
6.   
7. Private Sub Form1_Load(ByVal sender As System.Object, _   
8.                        ByVal e As System.EventArgs) _   
9.                        Handles MyBase.Load   
10.     TextBox1.Text = " Un texto "  
11. End Sub  
 4 - Evitar el BEEP al apretarEnter 
1. Private Sub TextBox1_KeyPress(ByVal sender As Object, _   
2.                            ByVal e As System.Windows.Forms.KeyPressEventArgs) _   
3.                               Handles TextBox1.KeyPress   
4.     If e.KeyChar = Convert.ToChar(Keys.Return) Then  
5.         e.Handled = True  
6.     End If  
7. End Sub    
 5 - Mayúsculas y minúsculas con Uppery Lower
 ' Mayúsculas   
1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _   
2.                                  ByVal e As System.EventArgs) _   
3.                                  Handles TextBox1.TextChanged   
4.     TextBox1.CharacterCasing = CharacterCasing.Upper   
5. End Sub  
6.   
7. 'Minusculas :   
8.   
9.Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _   
10.                                  ByVal e As System.EventArgs) _   
11.                                  Handles TextBox1.TextChanged   
12.     TextBox1.CharacterCasing = CharacterCasing.Lower   
13. End Sub     
  6 - Guardar el texto de un textbox en un archivo .txt
Colocar un...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Validaciones
  • Validad
  • Validaciones
  • Validar formularios
  • validar bachillerato
  • Validar pdt
  • ValiDes De La Guerra
  • Validar Oiniones

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS