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添加引用,别的项目就可以调用

  • 相关阅读:
    设计模式笔记4(工厂模式)
    设计模式笔记4(工厂模式)
    以前写的东东,放在这里个索引吧
    sicily 1001. Black Magic
    沙漠之旅
    hdu 1395(2^x mod n = 1)
    hdu 2161(Primes)
    sicily 8058. Matrix
    十进制转换为二进制
    硬币水题II
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/12256482.html
Copyright © 2011-2022 走看看