C# 中可以抽象 Windows.Forms.Panel 吗?
我正在尝试创建一个程序,该程序具有多层控件,所有控件都在彼此之上绘制。我这样做的方式是,我有一个 windows.forms.panel,它是执行实际绘图的面板的容器(这样我可以对它们进行分层)。
对于进行绘图的面板,我有一个继承自windows.forms.panel(称为abstractPanel)的抽象类,我已将其停靠样式设置为“填充”。它重写了 onPaint 函数,在该函数中调用了我在子级中重写的抽象函数。
我遇到的问题是,当我将从 AbstractPanel 继承的控件添加到容器时,它没有显示(未调用 onPaint 函数)。
有什么建议吗?
我是否从Java的角度考虑太多并且需要使abstractPanel不抽象?
I am trying to create a program that has multiple layers of controls all drawing on top of each other. The way I'm doing this is that I have a windows.forms.panel that is a container for the panels doing the actual drawing (this way I can layer them).
For the panels doing the drawing I have an abstract class that inherits from windows.forms.panel (call it abstractPanel) that I have set the docking style to "fill". It overrides the onPaint function in which it calls an abstract function that I override in the children.
The problem I have is that when I add a control that inherits from abstractPanel to the container it isn't showing up (the onPaint function isn't being called).
Any suggestions?
Am I thinking about this too much from a Java perspective and need to make abstractPanel not abstract?
我在 Visual Studio WinForms 设计器中遇到了类似的问题:如果表单继承自抽象类,则它根本不会显示在设计器中。我不知道为什么,但出于某种原因 Windows 窗体不“喜欢”抽象类。尝试删除
abstract
关键字,如果这样做,它不会改变功能。I've had a similar issue with the Visual Studio WinForms designer: if a form inherits from an abstract class, it doesn't get shown in the designer at all. I don't know why, but for some reason Windows Forms doesn't "like" abstract classes. Try removing the
abstract
keyword, it won't change the functionality if you do.