Radtextbox allows you to enter shaping numbers and BACKSPACE keys

Source: Internet
Author: User

Do not spray, thank you!!!

Allow input of shaping numbers and BACKSPACE keys

Using System.Windows.Forms;

Namespace BaseDataMaintain.Views.Controls
{
<summary>
int input textbox
</summary>
public class TextIntNumBox:Telerik.WinControls.UI.RadTextBox
{
protected override void OnKeyPress (System.Windows.Forms.KeyPressEventArgs e)
{
Base. OnKeyPress (e);
Not allowed at the beginning.
if (SelectionStart = = 0)
{
if (E.keychar = = ' 0 ')
//{
E.handled = true;
Return
//}
if (E.keychar = = '-')
{
e.handled = false;
Return
}
if (E.keychar = = ' 1 '
|| E.keychar = = ' 2 '
|| E.keychar = = ' 3 '
|| E.keychar = = ' 4 '
|| E.keychar = = ' 5 '
|| E.keychar = = ' 6 '
|| E.keychar = = ' 7 '
|| E.keychar = = ' 8 '
|| E.keychar = = ' 9 '
|| E.keychar = = ' \b ')
{
e.handled = false;
Return
}
}

You can only follow after 0. Add 2014.11.27
if (this. Text.trim (). StartsWith ("0") && e.keychar! = ' \b ')
{
E.handled = true;
Return
}

Only numbers + Backspace
if (E.keychar = = ' 0 '
|| E.keychar = = ' 1 '
|| E.keychar = = ' 2 '
|| E.keychar = = ' 3 '
|| E.keychar = = ' 4 '
|| E.keychar = = ' 5 '
|| E.keychar = = ' 6 '
|| E.keychar = = ' 7 '
|| E.keychar = = ' 8 '
|| E.keychar = = ' 9 '
//|| E.keychar = = '. '
|| E.keychar = = ' \b ')
{
e.handled = false;
}
Else
{
E.handled = true;
}
}

Supports copy, clip, paste, Ctrl + A
protected override bool processCmdKey (ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (KeyData = = (Keys.control | KEYS.A))
{
This. SelectAll ();
}
if (KeyData = = (Keys.control | KEYS.C))
{
This. Copy ();
}
if (KeyData = = (Keys.control | keys.x))
{
This. Cut ();
}
if (KeyData = = (Keys.control | KEYS.V))
{
This. Paste ();
}
Return base. processCmdKey (ref msg, keyData);
}
}
}

Radtextbox allows you to enter shaping numbers and BACKSPACE keys

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.