All pastes #510902 Raw Edit

Macca

public text v1 · immutable
#510902 ·published 2007-05-26 04:02 UTC
rendered paste body
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox Sender = (sender as TextBox);

            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '.' && e.KeyChar != '-')
            {
                e.Handled = true;
            }

            if (e.KeyChar == '-' && Sender.SelectionStart > 0)
            {
                e.Handled = true;
            }

            if (e.KeyChar == '.' && Sender.Text.IndexOf('.') > 0)
            {
                e.Handled = true;
            }
        }