C # textbox allows only numbers

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using devcomponents. dotnetbar. controls;

Namespace windrilling. errorjudge. Class
{
Class clstxtoperate
{
# Region textboxx control can only input numeric Functions
// Only numeric functions can be input
Public static void inputnumonly (textboxx mychecnktxt, keypresseventargs E)
{
// Determine whether the key type is required.
If (INT) E. keychar <48 | (INT) E. keychar> 57) & (INT) E. keychar! = 8 & (INT) E. keychar! = 46)
E. Handled = true;

// Decimal point processing.
If (INT) E. keychar = 46) // decimal point
{
If (mychecnktxt. Text. Length <= 0)
E. Handled = true; // the decimal point cannot be the first.
Else
{
Float F;
Float oldf;
Bool b1 = false, b2 = false;
B1 = float. tryparse (mychecnktxt. Text, out oldf );
B2 = float. tryparse (mychecnktxt. Text + E. keychar. tostring (), Out F );
If (b2 = false)
{
If (b1 = true)
E. Handled = true;
Else
E. Handled = false;
}
}
}
}
# Endregion
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.