C # secondary controls

Achieve results:

1. Create a program WinFrom

2, add a class library

3, to add a component class library

4, a drag ErrorProvider from component to component class in the toolbox

 

 

Code section:

 

 

 MyTextBox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//添加Forms引用
using System.Windows.Forms;
namespace ClassLibrary2
{
    public partial class MyTextBox : TextBox
    {
        public MyTextBox()
        {
            InitializeComponent();
        }

        public MyTextBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        public int IsNull(string info)
        {
            if (this.Text.Trim().Length == 0)
            {
                this.Error.SetError(this, info);
                return 0;
            }
            else 
            {
                this.Error.SetError(this, string.Empty);
                return 1;
            }
        }

    }
}
View Code

 

Form1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace controls
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int the Result = the this .myTextBox1.IsNull ( " allowed transmit null value " );
             IF (the Result == . 1 )
            {
                this.myTextBox2.Text = this.myTextBox1.Text;
            }
            else
            { 
            // otherwise code execution 
            }
            
        }
    }
}
View Code

 

 

 

When not generating the dll files can be dragged past.

 

Guess you like

Origin www.cnblogs.com/Luck1996/p/12013687.html