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 OnKeyPress(KeyPressEventArgs e)
{
base.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