有使用 OpenNETCF.IOC.(UI) 库的 C# 项目 (.NET CF)。
实际情况:在基本表单中处理 OnKeyDown 事件并且可以引发自定义事件(例如,如果用户按下了 ESC 按钮)。此事件可以以后代形式处理。
重构后:Base Form 现在是容器表单。所有后代形式现在都是 SmartPart。我现在应该如何将自定义事件从容器表单提升到 SmartParts?
// Base form
private void BaseForm_KeyDown(object sender, KeyEventArgs e)
{
// Handle ESC button
if (e.KeyCode == Keys.Escape || e.KeyValue == SomeOtherESCCode)
{
this.ButtonESCClicked(sender, new EventArgs());
}
}
// Descendant form
private void frmMyForm_ButtonESCClicked(object sender, EventArgs e)
{
this.AutoValidate = AutoValidate.Disable;
...
}