zoukankan      html  css  js  c++  java
  • c#的委托和事件

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

    namespace GoldCubePos.App
    {
        public partial class Form1 : Form
        {

            private delegate void ShowName(object sender);//定义委托

            private event ShowName btnclick;//定义事件

            //调用的方法

            private void ShowButtonName(object sender)
            {
                Button btn = sender as Button;
                if (btn != null)
                {
                    MessageBox.Show("按钮名称是:" + btn.Text);
                }
            }

            public Form1()
            {
                InitializeComponent();

            }

            private void button1_Click(object sender, EventArgs e)
            {

                //System.Diagnostics.Process.Start("http://www.163.com");
                MessageBox.Show("我被点击了!!!");
                btnclick += ShowButtonName;//订阅事件
                btnclick(sender);

            }
        }
    }

  • 相关阅读:
    L1-021 重要的话说三遍
    L1-020 帅到没朋友
    pytest--钩子
    pytest--allure
    pytest--常用插件
    pytest--高级用法
    pytest--配置文件
    pytest--控制运行
    pytest--fixture
    pytest--使用前提
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2075513.html
Copyright © 2011-2022 走看看