zoukankan      html  css  js  c++  java
  • winform控件的二次开发

    添加:

    自定义验证代码:

     public partial class SuperTextBox : TextBox
        {
            public SuperTextBox()
            {
                InitializeComponent();
            }
    
            public SuperTextBox(IContainer container)
            {
                container.Add(this);
    
                InitializeComponent();
            }
    
            public int BeginCheckEmpty()
            {
                if (this.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this, "必填项不能为空!");
                    return 0;
                }
                else
                {
                    this.errorProvider1.SetError(this, string.Empty);
                    return 1;
                }
            }
    
            public int BeginCheckData(string regularExpress, string errorMsg)
            {
                if (BeginCheckEmpty() == 0) return 0;
                //正则表达式验证,忽略大小写
                Regex objRegex = new Regex(regularExpress, RegexOptions.IgnoreCase);
                if (!objRegex.IsMatch(this.Text.Trim()))
                {
                    this.errorProvider1.SetError(this, errorMsg);
                    return 0;
                }
                else
                {
                    this.errorProvider1.SetError(this, string.Empty);//清楚小圆点的错误提示
                    return 1;
                }
            }
        }
    

      调用:

     private void btnAdd_Click(object sender, EventArgs e)
            {
                int a = this.txtName.BeginCheckEmpty();
                int b = this.txtAge.BeginCheckEmpty();
    
                int c = this.txtAge.BeginCheckData(@"^[1-9]d*$", "年龄必须是正整数");
    
                int result = a * b *c;
                if (result != 0)
                {
                    MessageBox.Show("提交成功!", "提示信息");
                }
            }
    

      添加选项卡:把bll添加引用,别的项目就可以调用

  • 相关阅读:
    二叉排序树的最低公共祖先
    [jobdu]树中两个结点的最低公共祖先
    [jobdu]用两个栈实现队列
    [leetcode]Balanced Binary Tree
    [jobdu]从尾到头打印链表
    [leetcode]Flatten Binary Tree to Linked List
    [leetcode]Unique Binary Search Trees
    hdu 4059
    hdu 3972 1 M possible
    CF 317D Game with Powers
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/12256482.html
Copyright © 2011-2022 走看看