mandag 11. mai 2009

text num edit

private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.KeyPress += new KeyPressEventHandler(Form1_KeyPress);

decimal sum = decimal.Parse(textBox1.Text) + decimal.Parse(textBox2.Text);
label1.Text = sum.ToString();
}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar < '0') || (e.KeyChar > '9')) && (e.KeyChar!=(char)Keys.Back))
e.Handled = true;
}

Ingen kommentarer:

Legg inn en kommentar