Esto fue en las cajas de texto....
 '*****************************trabajo con las cajas para formatear importes
    Private Function ReFormat(ByVal sTxt As String) As String
        If Len(sTxt) > 1 Then
            sInputString = UnFormatText(sTxt)
        Else
            sInputString = sTxt
        End If
        ReFormat = SetColonAndDot(sInputString)
    End Function
    Private Function SetColonAndDot(ByVal sTxt As String) As String
        Dim lg As Integer
        lg = Len(sTxt)
        Select Case lg
            Case 0
                SetColonAndDot = "0,00" & sTxt
            Case 1
                SetColonAndDot = "0,0" & sTxt
            Case 2
                SetColonAndDot = "0," & sTxt
            Case Else
                If lg > 5 And lg < 9 Then
                    SetColonAndDot = Microsoft.VisualBasic.Left(sTxt, lg -
5) & "." & Microsoft.VisualBasic.Mid(sTxt, lg - 4, 3) & "," &
Microsoft.VisualBasic.Right(sTxt, 2)
                ElseIf lg > 8 And lg < 12 Then
                    SetColonAndDot = Microsoft.VisualBasic.Left(sTxt, lg -
8) & "." & Microsoft.VisualBasic.Mid(sTxt, lg - 7, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 4, 3) & "," &
Microsoft.VisualBasic.Right(sTxt, 2)
                ElseIf lg > 11 And lg < 15 Then
                    SetColonAndDot = Microsoft.VisualBasic.Left(sTxt, lg -
11) & "." & Microsoft.VisualBasic.Mid(sTxt, lg - 10, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 7, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 4, 3) & "," &
Microsoft.VisualBasic.Right(sTxt, 2)
                ElseIf lg > 14 Then
                    SetColonAndDot = Microsoft.VisualBasic.Left(sTxt, lg -
14) & "." & Microsoft.VisualBasic.Mid(sTxt, lg - 13, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 10, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 7, 3) & "." &
Microsoft.VisualBasic.Mid(sTxt, lg - 4, 3) & "," &
Microsoft.VisualBasic.Right(sTxt, 2)
                Else
                    SetColonAndDot = Microsoft.VisualBasic.Left(sTxt, lg -
2) & "," & Microsoft.VisualBasic.Right(sTxt, 2)
                    ' SetColonAndDot = Microsoft.VisualBasic.Mid(sTxt,
Len(lg) - (Len(lg) - 1), 1) & "." & Microsoft.VisualBasic.Right(sTxt, 2) &
"," & "00"
                End If
        End Select
    End Function
    Private Function UnFormatText(ByVal sTxt As String) As String
        Dim i As Integer, sResult As String, sSign As String, bZerosDone As
Boolean
        sResult = ""
        For i = 1 To Len(sTxt)
            sSign = Mid(sTxt, i, 1)
            If sSign <> "," And sSign <> "." Then
                'cuts out all dots and colons
                If sSign <> "0" Or bZerosDone Then
                    ' cuts out all zeros until another number follows
                    sResult = sResult & sSign
                    bZerosDone = True
                End If
            End If
        Next
        UnFormatText = sResult
    End Function


    Private Sub txtPercepIva_TextChanged(sender As Object, e As EventArgs)
Handles txtPercepIva.TextChanged
        If Me.txtPercepIva.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtPercepIva.Text = ReFormat(Me.txtPercepIva.Text)
            ' setting Cursor back to the end of the number
            Me.txtPercepIva.SelectionStart = Len(Me.txtPercepIva.Text)
            Me.txtPercepIva.SelectionLength = 0
        End If
    End Sub
    Private Sub txtPercepIva_GotFocus(sender As Object, e As EventArgs)
Handles txtPercepIva.GotFocus
        Me.txtPercepIva.SelectionStart = 0
        Me.txtPercepIva.SelectionLength = Len(Me.txtPercepIva.Text)
    End Sub

    Private Sub txtPercepIva_KeyPress(sender As Object, e As
KeyPressEventArgs) Handles txtPercepIva.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtPercepIva_LostFocus(sender As Object, e As EventArgs)
Handles txtPercepIva.LostFocus
        ModificarTotales()
    End Sub

    Private Sub txtPbase_GotFocus(sender As Object, e As EventArgs) Handles
txtPbase.GotFocus
        Me.txtPbase.SelectionStart = 0
        Me.txtPbase.SelectionLength = Len(Me.txtPbase.Text)
    End Sub

    Private Sub txtPbase_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txtPbase.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub


    Private Sub txtPbase_TextChanged(sender As Object, e As EventArgs)
Handles txtPbase.TextChanged
        If Me.txtPbase.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtPbase.Text = ReFormat(Me.txtPbase.Text)
            ' setting Cursor back to the end of the number
            Me.txtPbase.SelectionStart = Len(Me.txtPbase.Text)
            Me.txtPbase.SelectionLength = 0
        End If
    End Sub

    Private Sub txtiva_GotFocus(sender As Object, e As EventArgs) Handles
txtiva.GotFocus
        Me.txtiva.SelectionStart = 0
        Me.txtiva.SelectionLength = Len(Me.txtiva.Text)
    End Sub

    Private Sub txtiva_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txtiva.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtiva_LostFocus(sender As Object, e As EventArgs) Handles
txtiva.LostFocus
        ModificarTotales()
    End Sub

    Private Sub txtiva_TextChanged(sender As Object, e As EventArgs)
Handles txtiva.TextChanged
        If Me.txtiva.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtiva.Text = ReFormat(Me.txtiva.Text)
            ' setting Cursor back to the end of the number
            Me.txtiva.SelectionStart = Len(Me.txtiva.Text)
            Me.txtiva.SelectionLength = 0
        End If
    End Sub
    '******************************ImpInt

    Private Sub txtimpint_GotFocus(sender As Object, e As EventArgs)
Handles txtImpInt.GotFocus
        Me.txtImpInt.SelectionStart = 0
        Me.txtImpInt.SelectionLength = Len(Me.txtiva.Text)
    End Sub

    Private Sub txtimpint_KeyPress(sender As Object, e As
KeyPressEventArgs) Handles txtImpInt.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtimpint_LostFocus(sender As Object, e As EventArgs)
Handles txtImpInt.LostFocus
        ModificarTotales()
    End Sub

    Private Sub txtimpint_TextChanged(sender As Object, e As EventArgs)
Handles txtImpInt.TextChanged
        If Me.txtImpInt.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtImpInt.Text = ReFormat(Me.txtImpInt.Text)
            ' setting Cursor back to the end of the number
            Me.txtImpInt.SelectionStart = Len(Me.txtImpInt.Text)
            Me.txtImpInt.SelectionLength = 0
        End If
    End Sub

'*****************IB************************************************************************************

    Private Sub txtib_GotFocus(sender As Object, e As EventArgs) Handles
txtIB.GotFocus
        Me.txtIB.SelectionStart = 0
        Me.txtIB.SelectionLength = Len(Me.txtIB.Text)
    End Sub

    Private Sub txtib_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txtIB.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtib_LostFocus(sender As Object, e As EventArgs) Handles
txtIB.LostFocus
        ModificarTotales()
    End Sub

    Private Sub txtib_TextChanged(sender As Object, e As EventArgs) Handles
txtIB.TextChanged
        If Me.txtIB.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtIB.Text = ReFormat(Me.txtIB.Text)
            ' setting Cursor back to the end of the number
            Me.txtIB.SelectionStart = Len(Me.txtIB.Text)
            Me.txtIB.SelectionLength = 0
        End If
    End Sub

'********************Descuento**************************************************************************

    Private Sub txtDto_GotFocus(sender As Object, e As EventArgs) Handles
txtDto.GotFocus
        Me.txtDto.SelectionStart = 0
        Me.txtDto.SelectionLength = Len(Me.txtDto.Text)
    End Sub

    Private Sub txtDto_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txtDto.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtDto_LostFocus(sender As Object, e As EventArgs) Handles
txtDto.LostFocus
        ModificarTotales()
    End Sub

    Private Sub txtDto_TextChanged(sender As Object, e As EventArgs)
Handles txtDto.TextChanged
        If Me.txtIB.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txtDto.Text = ReFormat(Me.txtDto.Text)
            ' setting Cursor back to the end of the number
            Me.txtDto.SelectionStart = Len(Me.txtDto.Text)
            Me.txtDto.SelectionLength = 0
        End If
    End Sub

'*****************************************TOTAL******************************************************************

    Private Sub txttotal_GotFocus(sender As Object, e As EventArgs) Handles
txttotal.GotFocus
        Me.txttotal.SelectionStart = 0
        Me.txttotal.SelectionLength = Len(Me.txttotal.Text)
    End Sub

    Private Sub txttotal_KeyPress(sender As Object, e As KeyPressEventArgs)
Handles txttotal.KeyPress
        If Not IsNumeric(e.KeyChar) And Not (e.KeyChar = ControlChars.Back)
Then
            e.Handled = True
        End If
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txttotal_TextChanged(sender As Object, e As EventArgs)
Handles txttotal.TextChanged
        If Me.txttotal.Text = "" Then Exit Sub
        If bJustChanged Then
            bJustChanged = False
        Else
            bJustChanged = True
            Me.txttotal.Text = ReFormat(Me.txttotal.Text)
            ' setting Cursor back to the end of the number
            Me.txttotal.SelectionStart = Len(Me.txttotal.Text)
            Me.txttotal.SelectionLength = 0
        End If
    End Sub

'----Esto en load del principal....
 Private Sub FormPrincipal_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = New
CultureInfo("es-ES")

System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator
= ","

System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator
= "."

    End Sub

' y esto para tomar los valores.......................
 Convert.ToDouble(Me.txtPbase.Text, CultureInfo.CurrentCulture)

asi lo logre, aunque reconozco que la solución de Marcelo era mejor...


El 10 de diciembre de 2014, 9:51, Pablo Marzullo <[email protected]>
escribió:

> Diego, estaría bueno que aportes detalles de como lo resolviste.
>
>
> Saludos, Pablo
>
>
> ---- Original Message ----
> *From*: Diego Spinedi <[email protected]>
> *To*: [email protected]
> *Sent*: Mie, Dic 10, 2014, 9:44 AM
> *Subject*: [puntonet] Consulta
>
> No, debido a que tenia muchas textbox no cambie por la función de Marcelo.
> La probe en un poryecto aparte y me funciono, pero antes de cambiar todos
> los textbox que tenia, utilice la cultura de la aplicación y aparentemente
> funcionó. Obviamente tengo formateos y demás en los textbox...
> ¿¿Fui claro??
>
> Saludos
>
> Diego
>
> El 9 de diciembre de 2014, 16:36, Cristian <[email protected]>
> escribió:
>
>> Diego, perdoname la re-pregunta, no entiendo cómo lo solucionaste, ¿fue
>> utilizando el NumericTextbox que extiende de Textbox que aportó Marcelo más
>> tu configuración de Cutlure?
>>
>>
>>
>> Gracias,
>>
>>
>>
>> Cristian.
>>
>>
>>
>> *De:* [email protected] [mailto:[email protected]] *En nombre de *Diego
>> Spinedi
>> *Enviado el:* martes, 09 de diciembre de 2014 07:50
>> *Para:* [email protected]
>> *Asunto:* [puntonet] Consulta
>>
>>
>>
>> Listeros: buenos dias. Queria agradecer los aportes que me han realizado
>> para poder solucionar el problema. Finalmente (creo) haberlo resuelto con
>> la clase System.Globalization definiendo la cultura de mi aplicación. Me
>> dió bastante trabajo pero creo que funcionaron todos los casos...de todas
>> maneras mi usuario será quien me de la última palabra,....
>>
>> Gracias a todos!!!
>>
>> Saludos
>>
>> Diego
>>
>>
>>
>> El 5 de diciembre de 2014, 15:00, Diego Spinedi <[email protected]>
>> escribió:
>>
>> Muy amable Marcelo! gracias !
>>
>> Lo voy a probar y luego te aviso como me fue!
>>
>>
>>
>> El 5 de diciembre de 2014, 14:43, Marcelo Abosch <
>> [email protected]> escribió:
>>
>> Hace mucho hice esta clase fijate si te sirve
>>
>>
>>
>>
>>
>>
>>
>> using System;
>>
>> using System.Collections.Generic;
>>
>> using System.Linq;
>>
>> using System.Text;
>>
>> using System.Windows.Forms;
>>
>> using System.Globalization;
>>
>>
>>
>> namespace App
>>
>> {
>>
>>     public class NumericTextBox : TextBox
>>
>>     {
>>
>>         bool allowSpace = false;
>>
>>
>>
>>         public NumericTextBox()
>>
>>         {
>>
>>             this.TextAlign = HorizontalAlignment.Right;
>>
>>         }
>>
>>
>>
>>         protected override void OnLeave(EventArgs e)
>>
>>         {
>>
>>             base.OnLeave(e);
>>
>>             if (!string.IsNullOrWhiteSpace(this.Text))
>>
>>             {
>>
>>                 this.Text = decimal.Parse(this.Text).ToString("0.00");
>>
>>             }
>>
>>         }
>>
>>
>>
>>         protected override void OnTextChanged(EventArgs e)
>>
>>         {
>>
>>
>>
>>             NumberFormatInfo numberFormatInfo = System.Globalization.
>> CultureInfo.CurrentCulture.NumberFormat;
>>
>>             string decimalSeparator =
>> numberFormatInfo.NumberDecimalSeparator;
>>
>>             if (this.Text.IndexOf(decimalSeparator) > -1)
>>
>>             {
>>
>>                 var decimals = this.Text.Substring(this
>> .Text.IndexOf(decimalSeparator)+1);
>>
>>                 if (decimals.Length > 2)
>>
>>                 {
>>
>>
>>
>>                     this.Text = this.Text.Substring(0, this.Text.Length
>> - 1);
>>
>>                     this.SelectionStart = this.Text.Length;
>>
>>                     this.SelectionLength = 0;
>>
>>                 }
>>
>>             }
>>
>>             base.OnTextChanged(e);
>>
>>
>>
>>
>>
>>         }
>>
>>
>>
>>
>>
>>         protected override void X_OnKeyPress(KeyPressEventArgs e)
>>
>>         {
>>
>>             base.X_OnKeyPress(e);
>>
>>
>>
>>             NumberFormatInfo numberFormatInfo = System.Globalization.
>> CultureInfo.CurrentCulture.NumberFormat;
>>
>>             string decimalSeparator =
>> numberFormatInfo.NumberDecimalSeparator;
>>
>>             string groupSeparator =
>> numberFormatInfo.NumberGroupSeparator;
>>
>>             string negativeSign = numberFormatInfo.NegativeSign;
>>
>>
>>
>>             string keyInput = e.KeyChar.ToString();
>>
>>
>>
>>             if (Char.IsDigit(e.KeyChar))
>>
>>             {
>>
>>                 // Digitos  OK
>>
>>             }
>>
>>             else if (keyInput.Equals(decimalSeparator))
>>
>>             {
>>
>>                 // Decimal separator  OK
>>
>>             }
>>
>>             else if (e.KeyChar == '\b')
>>
>>             {
>>
>>                  // Backspace  OK
>>
>>             }
>>
>>             else if (this.allowSpace && e.KeyChar == ' ')
>>
>>             {
>>
>>
>>
>>             }
>>
>>             else
>>
>>             {
>>
>>                 e.Handled = true;
>>
>>             }
>>
>>         }
>>
>>
>>
>>         public int IntValue
>>
>>         {
>>
>>             get
>>
>>             {
>>
>>                 return Int32.Parse(this.Text);
>>
>>             }
>>
>>         }
>>
>>
>>
>>         public decimal DecimalValue
>>
>>         {
>>
>>             get
>>
>>             {
>>
>>                 if (string.IsNullOrWhiteSpace(this.Text))
>>
>>                 {
>>
>>                     return Decimal.Parse("0");
>>
>>                 }
>>
>>                 else
>>
>>                 {
>>
>>                     return Decimal.Parse(this.Text);
>>
>>                 }
>>
>>             }
>>
>>         }
>>
>>
>>
>>         public bool AllowSpace
>>
>>         {
>>
>>             set
>>
>>             {
>>
>>                 this.allowSpace = value;
>>
>>             }
>>
>>
>>
>>             get
>>
>>             {
>>
>>                 return this.allowSpace;
>>
>>             }
>>
>>         }
>>
>>     }
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> *From:* [email protected] [mailto:[email protected]] *On Behalf Of *Diego
>> Spinedi
>> *Sent:* Friday, December 05, 2014 2:28 PM
>> *To:* [email protected]
>> *Subject:* [puntonet] Consulta
>>
>>
>>
>> Excatamente lo que acabas de definir. Deberia ser un textbox que acepte
>> decimales, las teclas de  cursor+borrado+suprimir+enter+punto  y que
>> convierta el punto  en coma.
>>
>>
>>
>> El 5 de diciembre de 2014, 14:21, Pablo Marzullo <[email protected]>
>> escribió:
>>
>> Hola Diego, pasa mas detalles... el control sobre el que queres validar
>> es un Textbox? que queres que valide? que solo tome números, acepte las
>> teclas del cursor+borrado+suprimir+enter+punto (y que cuando presionas coma
>> lo convierta a punto o la inversa) es eso??
>>
>>
>>
>> Saludos, Pablo
>>
>>
>>
>> *IAV Tech*
>>
>> Mendoza 246, (1838) Luis Guillon, Bs As, Argentina
>>
>> www.iav-tech.com
>>
>> Cel.: 011-1566721644
>>
>>
>>
>> ---- Original Message ----
>> *From*: Diego Spinedi <[email protected]>
>> *To*: [email protected]
>> *Sent*: Vie, Dic 5, 2014, 2:15 PM
>> *Subject*: [puntonet] Consulta
>>
>> Estoy desarrollando en winforms..
>>
>> Gracias!!!
>>
>>
>>
>> El 5 de diciembre de 2014, 9:40, Leandro Halfon <[email protected]>
>> escribió:
>>
>> Diego,
>>
>>
>>
>> ¿Estas en entorno web o winforms?
>>
>>
>>
>> 2014-12-05 9:33 GMT-03:00 Diego Spinedi <[email protected]>:
>>
>> Listeros: Estoy armando una aplicación de facturación y me encuentro con
>> el inconveniente de que no encuentro un control adecuado para los importes.
>> Lo termine haciendo con los text...pero alguien tiene alguna recomendación
>> sobre algun control que no me genere dolores de cabeza con los formatos y
>> validaciones????
>>
>>
>>
>> Gracias!!!
>>
>>
>>
>> --
>>
>> Diego Spinedi
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>> Diego Spinedi
>>
>>
>>
>>
>>
>> --
>>
>> Diego Spinedi
>>
>>
>>
>>
>>
>> --
>>
>> Diego Spinedi
>>
>>
>>
>>
>>
>> --
>>
>> Diego Spinedi
>> ------------------------------
>>
>> Se certificó que el correo no contiene virus.
>> Comprobada por AVG - www.avg.es
>> Versión: 2015.0.5577 / Base de datos de virus: 4235/8701 - Fecha de la
>> versión: 08/12/2014
>>
>
>
>
> --
> Diego Spinedi
>
>


-- 
Diego Spinedi

Responder a