110,499
社区成员
发帖
与我相关
我的任务
分享
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);
}
}
}
}