Error loading profile

If you have a question about the software please ask it here.

Re: Error loading profile

Postby Dan911 » Fri Mar 10, 2017 6:41 pm

cncdrive wrote:Hi Dan,

I think it would be even better to not even allow users to type in other than numbers if the textbox has to contain a number only.
Here is a little function for you which checks if the keys the user pressed are numeric characters and not allowing other characters to be inserted into the checkbox:

Code: Select all
private void Checkifnumber(object sender, KeyPressEventArgs e)
{
      if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
      {
          e.Handled = true;
      }

     // only allow one decimal point
      if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))




















      {
          e.Handled = true;
      }
}


Just attach a Keypress Event to the textboxes of interest and call the above function.



Thanks works great, I modified slightly not to allow any decimals just numbers.

Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Previous

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 16 guests

cron