日期:2014-05-18 浏览次数:21214 次
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void myUserControl1_OnMyEvent(string text)
        {
            MessageBox.Show(text);
        }
        private void myUserControl2_OnMyEvent(string text)
        {
            MessageBox.Show(text);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            myUserControl1.MyEvent("123");
            myUserControl2.MyEvent("456");
        }
    }
    public class MyUserControl : UserControl
    {
        public delegate void MyDelegate(String text);
        public event MyDelegate OnMyEvent;
        public void MyEvent(String text)
        {
            if (OnMyEvent != null)
            {
                OnMyEvent(text);
            }
        }
    }
}