美文网首页
1123_C#_自定义事件

1123_C#_自定义事件

作者: Asa_Guo | 来源:发表于2017-04-18 08:41 被阅读0次
    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 Winform_EvnetTest
    {
        public partial class Form1 : Form
        {
            // 1.自定义事件
            public class TextChangeEventArgs : EventArgs
            {
                private string message;
                public TextChangeEventArgs(string message)
                {
                    this.message = message;
                }
    
                public string Message
                {
                    get { return message; }
                }
            }
    
            //2.1 定义委托
            public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
            //2.2 定义事件
            public event TextBoxChangedHandle UserControlValueChanged;
            //2.3 
            private void textBox1_TextChanged(object sender, System.EventArgs e)
            {
                if (UserControlValueChanged != null)
                    UserControlValueChanged(this, new TextChangeEventArgs(this.textBox1.Text));
    
                MessageBox.Show(this.textBox1.Text);
            }
    
            public Form1()
            {
                InitializeComponent();
    
                //3.注册事件
                this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            }
        }
    }
    
    

    相关文章

      网友评论

          本文标题:1123_C#_自定义事件

          本文链接:https://www.haomeiwen.com/subject/ickvpttx.html