Visual Studio 表单设计器显示控件列表
Visual Studio Form Designer Showing List of Controls
我知道让 Form Designer 工作是一件棘手的事情。泛型、x64、项目 XML 的微妙问题...但也许有人可以就我当前的问题提供建议,即我创建的组件继承自 TabPage
,当我尝试查看它时在设计器中显示为其控件列表,如下所示:
提前致谢。
您不能将 TabPage
作为设计器的根,但您可以对 Panel
或其他容器控件执行相同的操作。限制是因为,TabPage
只能承载在 TabControl
中,甚至不能承载在设计器的叠加控件中:
TabPage cannot be added to a
'System.Windows.Forms.Design.DesignerFrame+OverlayControl'. TabPages
can only be added to TabControls.
当控件的基础 class 具有 DocumentDesigner
类型的设计器时,控件可以显示为设计器的根。 Form
和 UserControl
是这样的控件,这意味着当您创建一个新的 Form1:Form
或新的 UserControl1:UserControl
时,因为基础 class 派生自可设计的控件,那么class 可以在设计器中作为 root 进行编辑。
我相信您可以使用 UserControl
来满足您的要求,但出于学习目的(或作为解决方法),如果您想使派生自 Panel
的控件可设计,您可以复制代码文件中的以下代码:
public class MyControl: MyDesignableControl
{
}
[Designer(typeof(DocumentDesigner), typeof(IRootDesigner))]
public class MyDesignableControl : Panel
{
}
然后保存然后双击就可以看到可以像root控件一样设计了
然后在完成设计后,将 Panel
更改为 TabPage
。
This designer is a root designer, meaning that it provides the
root-level design mode view for the associated document when it is
viewed in design mode.
You can associate a designer with a type using a
DesignerAttribute
.
For an overview of customizing design time behavior, see Extending
Design-Time
Support.
我知道让 Form Designer 工作是一件棘手的事情。泛型、x64、项目 XML 的微妙问题...但也许有人可以就我当前的问题提供建议,即我创建的组件继承自 TabPage
,当我尝试查看它时在设计器中显示为其控件列表,如下所示:
提前致谢。
您不能将 TabPage
作为设计器的根,但您可以对 Panel
或其他容器控件执行相同的操作。限制是因为,TabPage
只能承载在 TabControl
中,甚至不能承载在设计器的叠加控件中:
TabPage cannot be added to a 'System.Windows.Forms.Design.DesignerFrame+OverlayControl'. TabPages can only be added to TabControls.
当控件的基础 class 具有 DocumentDesigner
类型的设计器时,控件可以显示为设计器的根。 Form
和 UserControl
是这样的控件,这意味着当您创建一个新的 Form1:Form
或新的 UserControl1:UserControl
时,因为基础 class 派生自可设计的控件,那么class 可以在设计器中作为 root 进行编辑。
我相信您可以使用 UserControl
来满足您的要求,但出于学习目的(或作为解决方法),如果您想使派生自 Panel
的控件可设计,您可以复制代码文件中的以下代码:
public class MyControl: MyDesignableControl
{
}
[Designer(typeof(DocumentDesigner), typeof(IRootDesigner))]
public class MyDesignableControl : Panel
{
}
然后保存然后双击就可以看到可以像root控件一样设计了
然后在完成设计后,将 Panel
更改为 TabPage
。
This designer is a root designer, meaning that it provides the root-level design mode view for the associated document when it is viewed in design mode.
You can associate a designer with a type using a
DesignerAttribute
. For an overview of customizing design time behavior, see Extending Design-Time Support.