사용자 정의 컨트롤에 사용자 지정 이벤트를 제공하고 사용자 정의 컨트롤 내의 이벤트에서 이벤트를 호출하는 방법이 있습니까? (호출이 올바른 용어입니다 있는지 확실하지 않습니다)Winforms 사용자가 사용자 지정 이벤트를 제어합니다.
public partial class Sample: UserControl
{
public Sample()
{
InitializeComponent();
}
private void TextBox_Validated(object sender, EventArgs e)
{
// invoke UserControl event here
}
}
그리고 MainForm :
public partial class Sample: UserControl
{
public event EventHandler TextboxValidated;
public Sample()
{
InitializeComponent();
}
private void TextBox_Validated(object sender, EventArgs e)
{
// invoke UserControl event here
if (this.TextboxValidated != null) this.TextboxValidated(sender, e);
}
}
: 그리고
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
}
}
당신은 http://stackoverflow.com/questions/2151049/net-custom-event-organization-assistance –