您无需再次声明该事件。如果它是公共的并且在需要时已经被抛出,您可以根据需要通过订阅基类事件来处理更改。
我的意思是,您可以执行以下操作:
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);
}
}
}
qq_花开花谢_0
眼眸繁星
相关分类