zoukankan      html  css  js  c++  java
  • 委托

    1.简单委托

     一个控件buttion,属性名:委托简单用

    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 委托练习2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            //1.声明委托类(必须制定返回值类型 和方法 参数列表)
            public delegate void Dg(string pg);
            public delegate void DF();//没带参数委托
            private void button1_Click(object sender, EventArgs e)
            {
                //2.创建委托对象,并为委托添加一个方法指针(方法的地址)
                SayHi("啊啊啊!");
                Dg dg = new Dg(SayHi);//执行委托签名相同的方法
                DF df = new DF(Say);
               df();
            }
            public void SayHi(string ds)
            {
                MessageBox.Show("哈哈1"+ds);
            }
            public void Say()
            {
                MessageBox.Show("哈哈2");
            }
        }
    }
    结果如下:

    2.简单委托:委托和事件

     自定义:类c1Button,C1Button继承Forms.Button

    3.委托和事件

    结果是:

    4.委托和事件:委托做参数

    5.委托和事件:委托遍历集合

    6.委托和事件:委托做返回值

  • 相关阅读:
    font-weight(字体粗细)属性
    Node.js入门(三)
    js难点问题
    Node.js入门(二)
    Node.js入门(一)
    Reactjs的Controller View模式
    智能社的邀请码
    react native 学习资料汇总
    jquery操作select
    分享
  • 原文地址:https://www.cnblogs.com/hehehehehe/p/5778375.html
Copyright © 2011-2022 走看看