还在为用户控件中调用主窗体方法而头疼吗?
用户控件:UserControl 定义事件ChartClickEvent ,并重写EventArgs 看需要 用来传递参数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#region 自定义事件 Click
/// <summary>
/// 事件
/// </summary>
public event EventHandler ChartClickEvent;
public class ChartEventArgs : EventArgs
{
public string LotId { get; set; }
}
#endregion
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public void box_DblClick(object sender, EventArgs e)
{
try
{
ChartEventArgs eN = new ChartEventArgs();
eN.LotId = tmp.ToString();
if (ChartClickEvent != null)
{
ChartClickEvent(this, eN);
}
}
catch (Exception ex)
{
ExceptionBase.ExceptionHandler(ex);
}
}
父窗体事件中会生成 UserControl_ChartClickEvent 事件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private void UserControl_ChartClickEvent(object sender, EventArgs e)
{
// 获取参数
string lotID = ((TDWATBoxChart.ChartEventArgs)(e)).LotId;
MessageBox.Show("输出方法")
}