C#(winForm)子类继承父类事件

wozuiaijiahui 2012-11-21 10:15:13

public partial class BaseForm : UserControl
{
public bool mouseLeave = false;

#region ==鼠标进入事件==
protected void BaseForm _MouseEnter(object sender, EventArgs e)
{
mouseLeave = true;
}
#endregion

#region ==鼠标离开事件==
protected void BaseForm_MouseLeave(object sender, EventArgs e)
{
mouseLeave = false;
}
#endregion
}
public partial class SubForm : BaseForm
{
#region ==鼠标进入事件==
private void SubForm_MouseEnter(object sender, EventArgs e)
{
BaseForm_MouseEnter(sender, e);
}
#endregion

#region ==鼠标离开事件==
private void SubForm_MouseLeave(object sender, EventArgs e)
{
BaseForm_MouseLeave(sender, e);
}
#endregion

这样不行吗?为什么不能调用到父类的事件?怎么样继承父类的事件?
...全文
446 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dacan66 2012-11-21
  • 打赏
  • 举报
回复
写一个virtual函数,用来接收event 然后子类里,override
wozuiaijiahui 2012-11-21
  • 打赏
  • 举报
回复
在子类的事件中调用OVERRIDE方法?难道不能直接继承父类的事件吗?

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧