来自具有不同args的另一事件的Fire事件

时间:2018-01-27 06:31:55

标签: c# winforms

我想从另一个事件中触发事件。

private void ugTopActivity_FillSceneGraph(object sender, FillSceneGraphEventArgs e)
        {
            e.Something();
        }

private void ugTopActivity_ChartDataClicked(object sender, ChartDataEventArgs e)
            {
               //I need to fire FillSceneGraph event from here.
               ugTopActivity_ChartDataClicked(sender,e) // This doesn't work because 'e' Types are not convertable
            }

如何使用不同的eventargs类型从事件调用另一个?

2 个答案:

答案 0 :(得分:2)

我会增强@Ashkan Mobayen Khiabani的答案,正如他所说,您需要创建一个新的FillSceneGraphEventArgs对象并发送给ugTopActivity_ChartDataClicked

private void ugTopActivity_ChartDataClicked(object sender, ChartDataEventArgs e)
{
    //I need to fire FillSceneGraph event from here.
    var ev = new FillSceneGraphEventArgs(scene, core); // SceneGraph and ChartCore

    ugTopActivity_ChartDataClicked(sender, ev);
}

注意

  1. 这可能会以意想不到的方式崩溃或工作,因为您自己解雇了该事件。因此,请确保您获得适当或间接的SceneGraphChartCore

  2. 还要照顾发件人ugTopActivity_ChartDataClicked可以请求特定发件人对象类型

答案 1 :(得分:1)

如果您在null中未使用e,则可以使用ugTopActivity_FillSceneGraph

ugTopActivity_ChartDataClicked(sender, null);

否则,您可以自己创建事件参数:

FillSceneGraphEventArgs event = new FillSceneGraphEventArgs(parameters here); //I'm not familiar with this event so don't know its arguments
    ugTopActivity_ChartDataClicked(sender, event);