0
我正在開發一個應用程序,它有許多面板,全部來自BasePanel
用戶控件。
使用該應用程序與使用嚮導非常相似 - 每次在其他面板上方顯示不同面板時。
我想有一個計時器排序,所以當沒有用戶活動時,顯示第一個面板。在InitializeComponent之後調用基構造器
這裏是底板的代碼:
public partial class BasePanel : UserControl
{
private Timer timer = new Timer();
public BasePanel()
{
InitializeComponent();
timer.Interval = 5000;
timer.Tick += timer_Tick;
foreach (Control control in Controls)
control.Click += Control_Click;
}
public event EventHandler NoActivity = delegate { };
private void timer_Tick(object sender, EventArgs e)
{
NoActivity(this, EventArgs.Empty);
}
private void Control_Click(object sender, EventArgs e)
{
timer.Stop();
timer.Start();
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
timer.Start();
}
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
timer.Stop();
}
}
問題:
派生InitializeComponent()
被調用之前的BasePanel
構造函數被調用。
由於BasePanel
沒有自己的控制 - 沒有控制註冊到Control_Click
事件。
這是正常的繼承行爲,但仍然 - 我如何註冊派生類的控件在基類?