Usuário com melhor resposta
Maskedit com Decimal

Pergunta
-
Pessoal
Estava pensando em utilizar o maskedit com o Visual Studio 2010, para tratar valor decimal, só que não estou conseguindo a formatação correta, pois quando passo o valor não está ficando na formatação correta já tentei de diversas formas, alguém teria alguma ideia do que pode estar acontecendo.
Respostas
-
é porque aquele componente acaba te limitando pelo visto!
será que esse código não te ajuda: (Créditos colocado como forma de não plágio) Ref:
http://www.codeproject.com/Articles/8822/Automatically-put-decimal-for-currency-format-in-T
Apesar que eu utilize mas, eu alterei de evento e coloquei tudo no KeyPress ficou melhor!!! Assim logo
abaixo como eu utilizei
private bool IsNumeric(int Val) { return ((Val >= 48 && Val <= 57) || (Val == 8) || (Val == 46)); } private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { int KeyCode = (int)e.KeyChar; if (!IsNumeric(KeyCode)) { e.Handled = true; return; } else { e.Handled = true; } if (((KeyCode == 8) || (KeyCode == 46)) && (str.Length > 0)) { str = str.Substring(0, str.Length - 1); } else if (!((KeyCode == 8) || (KeyCode == 46))) { str = str + Convert.ToChar(KeyCode); } if (str.Length == 0) { textBox2.Text = ""; } if (str.Length == 1) { textBox2.Text = "0,0" + str; } else if (str.Length == 2) { textBox2.Text = "0," + str; } else if (str.Length > 2) { textBox2.Text = str.Substring(0, str.Length - 2) + "," + str.Substring(str.Length - 2); } }
- Marcado como Resposta Giovani Cr quinta-feira, 21 de novembro de 2013 12:38
Todas as Respostas
-
-
-
é porque aquele componente acaba te limitando pelo visto!
será que esse código não te ajuda: (Créditos colocado como forma de não plágio) Ref:
http://www.codeproject.com/Articles/8822/Automatically-put-decimal-for-currency-format-in-T
Apesar que eu utilize mas, eu alterei de evento e coloquei tudo no KeyPress ficou melhor!!! Assim logo
abaixo como eu utilizei
private bool IsNumeric(int Val) { return ((Val >= 48 && Val <= 57) || (Val == 8) || (Val == 46)); } private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { int KeyCode = (int)e.KeyChar; if (!IsNumeric(KeyCode)) { e.Handled = true; return; } else { e.Handled = true; } if (((KeyCode == 8) || (KeyCode == 46)) && (str.Length > 0)) { str = str.Substring(0, str.Length - 1); } else if (!((KeyCode == 8) || (KeyCode == 46))) { str = str + Convert.ToChar(KeyCode); } if (str.Length == 0) { textBox2.Text = ""; } if (str.Length == 1) { textBox2.Text = "0,0" + str; } else if (str.Length == 2) { textBox2.Text = "0," + str; } else if (str.Length > 2) { textBox2.Text = str.Substring(0, str.Length - 2) + "," + str.Substring(str.Length - 2); } }
- Marcado como Resposta Giovani Cr quinta-feira, 21 de novembro de 2013 12:38
-
-
- Editado Fulvio Cezar Canducci Dias terça-feira, 12 de novembro de 2013 20:50