jeric_mandrake
Nov 18th, 2007, 06:56 AM
Good day, I have a textbox with a default value of .00
All i want to do is if I have to enter a number BEFORE ".", it should be from right to left, And after the ".", it should be move from left to right, making the default "0" replace by the new number.
Like as show below:
<----- ----->
123456 . 00
so when I enter a new number after the decimal, the 00 will be replace.
And when I delete the value after the decimal, the default value of 00 will return.
I have a code here, but it generates some errors, is anyone could help me on my problem?
Thanks.
if (period == false)
{
textBox1.SelectionStart = textBox1.Text.Length - 3;
textBox1.SelectionLength = 0;
}
else
{
if (e.KeyChar != Convert.ToChar("."))
{
string tmp1 = textBox1.Text.Substring(0, this.textBox1.SelectionLength + 1);
string tmp2 = textBox1.Text.Substring(this.textBox1.SelectionLength + 1, this.textBox1.Text.Length - this.textBox1.SelectionLength - 1);
this.textBox1.Text = tmp1 + tmp2;
}
if (firstdig)
{
this.textBox1.SelectionStart = textBox1.Text.Length - 1;
this.textBox1.SelectionLength = 0;
firstdig = false;
}
else
{
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.SelectionLength = 0;
firstdig = true;period = false;
}
}
if (e.KeyChar == Convert.ToChar("."))
{
string tmp1 = textBox1.Text.Substring(0, this.textBox1.SelectionStart);string tmp2 = textBox1.Text.Substring(textBox1.SelectionStart + 1, textBox1.Text.Length - textBox1.SelectionStart - 1);
textBox1.Text = tmp1 + tmp2;
period = true;
this.textBox1.SelectionStart = textBox1.Text.Length - 2;
}
All i want to do is if I have to enter a number BEFORE ".", it should be from right to left, And after the ".", it should be move from left to right, making the default "0" replace by the new number.
Like as show below:
<----- ----->
123456 . 00
so when I enter a new number after the decimal, the 00 will be replace.
And when I delete the value after the decimal, the default value of 00 will return.
I have a code here, but it generates some errors, is anyone could help me on my problem?
Thanks.
if (period == false)
{
textBox1.SelectionStart = textBox1.Text.Length - 3;
textBox1.SelectionLength = 0;
}
else
{
if (e.KeyChar != Convert.ToChar("."))
{
string tmp1 = textBox1.Text.Substring(0, this.textBox1.SelectionLength + 1);
string tmp2 = textBox1.Text.Substring(this.textBox1.SelectionLength + 1, this.textBox1.Text.Length - this.textBox1.SelectionLength - 1);
this.textBox1.Text = tmp1 + tmp2;
}
if (firstdig)
{
this.textBox1.SelectionStart = textBox1.Text.Length - 1;
this.textBox1.SelectionLength = 0;
firstdig = false;
}
else
{
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.SelectionLength = 0;
firstdig = true;period = false;
}
}
if (e.KeyChar == Convert.ToChar("."))
{
string tmp1 = textBox1.Text.Substring(0, this.textBox1.SelectionStart);string tmp2 = textBox1.Text.Substring(textBox1.SelectionStart + 1, textBox1.Text.Length - textBox1.SelectionStart - 1);
textBox1.Text = tmp1 + tmp2;
period = true;
this.textBox1.SelectionStart = textBox1.Text.Length - 2;
}