• RadTextBox允许输入整形数字以及退格键


    勿喷,谢谢!!!

    //允许输入整形数字以及退格键

    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);
    //开头不允许出现.
    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;
    }
    }

    //0后只可以跟. add 2014.11.27
    if (this.Text.Trim().StartsWith("0") && e.KeyChar != '\b')
    {
    e.Handled = true;
    return;
    }

    //只能数字 + 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;
    }
    }

    //支持复制、剪贴、黏贴、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);
    }
    }
    }

     

    博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
  • 相关阅读:
    c学习第3天
    [BZOJ2124] 等差子序列
    CF710F String Set Queries
    Cow Hopscotch (dp+树状数组优化)
    CF528D Fuzzy Search (bitset)
    Gym 101667L Vacation Plans (dp)
    Codeforces 432D Prefixes and Suffixes (kmp+dp)
    [题解]BZOJ2115 XOR
    洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
    从中国矢量图筛选出江苏省行政区划图
  • 原文地址:https://www.cnblogs.com/YYkun/p/5653965.html
Copyright © 2020-2023  润新知