Ver Mensaje Individual
  #6 (permalink)  
Antiguo 03/12/2010, 06:17
ncmaster
 
Fecha de Ingreso: octubre-2009
Mensajes: 30
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Formato de decimales en textbox

Hola, yo he usado el MaskedTextBox y en verdad no me gusta, asi que lo hago de esta forma, espeo te sirva.


Código vb:
Ver original
  1. 'Tb_cantidad ==> TextBox donde ingresamos los valores.
  2. 'Tb_precio   ==> Siguiente TextBox despues de precionar el Enter
  3.  
  4. Private Sub Tb_cantidad_KeyPress(ByVal sender As Object, ByVal e As _
  5.             System.Windows.Forms.KeyPressEventArgs) Handles Tb_cantidad.KeyPress
  6.         If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
  7.             e.Handled = True
  8.             If Tb_cantidad.Text = CChar("") Then
  9.                 Tb_cantidad.Text = "0"
  10.             End If
  11.             Tb_cantidad.Text = Format(Tb_cantidad.Text, "###,##0.00")
  12.             Tb_precio.Focus()
  13.         End If
  14.  
  15. ' "0123456789.-" Valores o caracteres que solo aceptara el TextBox
  16.  
  17.         If InStr(1, "0123456789.-" & Chr(8), e.KeyChar) = 0 Then
  18.             e.Handled = True
  19.             e.KeyChar = CChar("")
  20.         End If
  21.     End Sub


Saludos.