C#复合事件

时间:2015-04-08 12:14:51

标签: c# user-controls compact-framework

我正在创建一个UserControl,其中包含其他控件。我想创建一些形式的"复合"使用UserControl提供表单的事件。

例如:我在UserControl内有很多面板。我在EventHandler内创建了一个UserControl来处理这些面板的所有MouseDown事件。最后,我想让UserControl上的所有MouseDown事件在父级上显示为MouseDown

我可以在此MousePressed上创建一个类似UserControl的新活动,但我更愿意使用现有名称MouseDown。我如何声明这个新事件以便隐藏"已经存在的另一个MouseDown事件?

我希望我能够解释我的问题。

提前致谢。

1 个答案:

答案 0 :(得分:1)

注册UserControl中所需的所有事件(UserControl本身除外,这将是在父表单上注册所需的事件。)

大多数事件似乎都有一种用来调用它们的方法。您可以从“开启”开始调用此方法。例如:OnMousePressed

// You can register all MouseDown Events you need in one EventHandler.
private void Item_MouseDown(object sender, MouseEventArgs e)
{
    // Call this method to call the UserControls event.
    this.OnMouseDown(e); 

    // Register to the UserControl's MouseDown event where you want to catch it.
}