继承的成员由winforms生成的代码自动隐藏

本文关键字:代码 隐藏 成员 winforms 继承 | 更新日期: 2023-09-27 18:28:21

我有两个多个子类链接到一个父类,它们都是winform类。问题在于所有类中自动生成的代码,该代码具有以下公共签名:

/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor.
/// </summary>
//member inherited and hides parent's, however both derived and parent method are in designer sections (don't edit).
private new void InitializeComponent()
{
 //auto-generated logic
}

根据我想要消除的编译器警告:

Warning: 'Project.Windows.Forms.FirstChildClass.InitializeComponent()' hides inherited member 'Project.ParentClass.InitializeComponent()'. Use the new keyword if hiding was intended.

我需要子逻辑来隐藏父逻辑,我在上面的代码中通过添加新的关键字实现了这一点。我只是担心这可能会对Winforms产生不利影响;由于自动生成的注释声明不应该对其进行编辑。

继承的成员由winforms生成的代码自动隐藏

除非父成员标记为virtual,否则不能覆盖它们。如果隐藏父成员,则当从子类调用该方法时,将使用子方法。只有当父方法调用时,才会调用父方法。

如果你能更具体地说明你想"覆盖"父类中的哪些行为,那么可能有另一种方法来解决你的问题。