bool[] bIsNum;
string strTemp = string.Empty;
private void textBox1_TextChanged(object sender, EventArgs e)
{
bIsNum = new bool[textBox1.Text.Length];
for (int i = 0; i < bIsNum.Length; i++)
{
bIsNum[i] = false;
}
int n = 0;
foreach (char c in textBox1.Text)
{
for (int i = 0; i <= 9; i++)
{
if (c.ToString() == i.ToString())
{
bIsNum[n] = true;
break;
}
}
n++;
}
foreach (bool b in bIsNum)
{
if (b == false)
{
textBox1.Text = strTemp;
break;
}
}
strTemp = textBox1.Text;
textBox1.SelectionStart = textBox1.Text.Length;
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar=='.' && this.textBox1.Text.IndexOf(".")!=-1)
{
e.Handled=true;
}
if(!((e.KeyChar>=48 && e.KeyChar<=57) || e.KeyChar=='.' || e.KeyChar==8))
{
e.Handled=true;
}
}