您不需要再次声明事件。如果它是公共的,并且在需要时已经被抛出,则可以通过订阅基类事件来处理更改(如果需要)。
我的意思是,你可以做如下的事情:
using System;
using System.Windows.Forms;
namespace DRT
{
internal abstract partial class DRT_ComboBox_Abstract : ComboBox
{
public DRT_ComboBox_Abstract()
{
InitializeComponent();
SelectedValueChanged += MyOwnHandler
}
protected virtual void MyOwnHandler(object sender, EventArgs args)
{
// Hmn.. now I know that the selection has changed and can so somethig from here
// This method is acting like a simple client
}
}
}
论
S
O
LID
课程(我相信是这样的
ComboBox
)通常,有效地调用订阅服务器来处理某些事件的方法通常是虚拟的,允许您在继承此类之后截获事件处理程序调用(如果需要)。
它是:
using System;
using System.Windows.Forms;
namespace DRT
{
internal abstract partial class DRT_ComboBox_Abstract : ComboBox
{
public DRT_ComboBox_Abstract()
{
InitializeComponent();
}
protected override void OnSelectedValueChanged(object sender, EventArgs args)
{
// Wait, the base class is attempting to notify the subscribers that Selected Value has Changed! Let me do something before that
// This method is intercepting the event notification
// Do stuff
// Continue throwing the notification
base.OnSelectedValueChanged(sender, args);
}
}
}
注意:我已经移除了
Disable
方法只用于代码简化。这件事不在范围之内
希望有帮助。