文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c#父子窗体间的自定义事件(static)

c#父子窗体间的自定义事件(static)

时间:2011-01-05  来源:cexoyq



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

namespace ppop_client
{
    public partial class MDI : Form
    {
        private int childFormNumber = 0;

        public MDI()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            // 创建此子窗体的一个新实例。

            Form childForm = new Form1();
            // 在显示该窗体前使其成为此 MDI 窗体的子窗体。

            childForm.MdiParent = this;
            childForm.Text = "窗口" + childFormNumber++;

            childForm.Show();
        }
//根据委托定义事件
public static event meEventHandler me1;
//按钮引发事件
        private void toolStripButton_test_Click(object sender, EventArgs e)
        {
            if (me1 != null)
                me1(0);
        }
    }
}



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

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

             //注册事件到本类的onme1函数
                MDI.me1+=new meEventHandler(onme1);
        }
            //事件处理
        public void onme1(object o)
        {
            label1.Text = "heheh";
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        
    }
}


using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace ppop_client
{

//定义一个委托
    public delegate void meEventHandler(object o);

    static class Program
    {
        /// <summary>

        /// 应用程序的主入口点。

        /// </summary>

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MDI());
        }
    }
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载