【发布时间】:2011-01-12 09:11:49
【问题描述】:
有没有办法给用户控件自定义事件,并在用户控件内的事件上调用事件。 (我不确定调用是否正确)
public partial class Sample: UserControl
{
public Sample()
{
InitializeComponent();
}
private void TextBox_Validated(object sender, EventArgs e)
{
// invoke UserControl event here
}
}
主窗体:
public partial class MainForm : Form
{
private Sample sampleUserControl = new Sample();
public MainForm()
{
this.InitializeComponent();
sampleUserControl.Click += new EventHandler(this.CustomEvent_Handler);
}
private void CustomEvent_Handler(object sender, EventArgs e)
{
// do stuff
}
}
【问题讨论】:
-
您可能会发现这个问题的第一个答案很有用stackoverflow.com/questions/2151049/…
标签: c# .net winforms user-controls event-handling