--
Has recibido este mensaje porque estás suscrito al grupo "C#.NET Latinoamérica" de Grupos de Google.
Visita este grupo en http://groups.google.com/group/vfp-a-csharpnet.
floating.ToString("C", ci)); // Displays "C: $10,761.94"
Cadenas con formato numérico estándar
http://msdn.microsoft.com/es-es/library/dwhawy9k(v=vs.90).aspx
Ok probare y comento.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
TextBox tb = sender as TextBox;
string tbFormat = "$ ###,###,###.00" as String;
string[] tbFmParts = tbFormat.Replace(",", "").Split('.').replace("$","") as string[];
int lenEntero = 16;
int lenDecimal = 0;
//Determina la Longiktud del calor en la parte entera y en la decimal.
if (tbFmParts.Length >0)
{ lenEntero = tbFmParts[0].Length;
if (tbFmParts.Length >1)
{
lenDecimal = tbFmParts[1].Length;
}
}
//Controlar que no se teclee mas de un punto decimal.
if ((ch == 46) && (tb.Text.IndexOf('.') != -1)) { e.Handled = true; }
//Controla que solo acepte números
if (!Char.IsDigit(ch) && ch != 8 && ch != 46) { e.Handled = true; }
//Controlar longitud del valor tecleado
if (Char.IsDigit(ch) || ch==46)
{ string result = tb.Text.Substring(0, tb.SelectionStart)
+ e.KeyChar
+ tb.Text.Substring(tb.SelectionStart
+ tb.SelectionLength);
string[] parts = result.Split('.') as string[];
if (parts.Length > 0)
{
// Controlar la cantidad de números enteros tecleado.
if (parts[0].Length > lenEntero) { e.Handled = true; }
if (parts.Length > 1)
{
// Controlar la cantidad de decimales tecleado.
if (parts[1].Length > lenDecimal) { e.Handled = true; }
}
}
}
}
private void textBox1_Leave(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
Double valor = Convert.ToDouble(tb.Text);
String tbFormat = "$ ###,###,###.00" as string;
tb.Text = valor.ToString(tbFormat);
}
private void textBox1_Enter(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
tb.Text = tb.Text.Replace(",","").Replace("$","");
}