简体   繁体   English

Visual Studio 2008:将组件添加到继承的面板

[英]Visual Studio 2008: Adding components to inherited panel

In this scenario I have a base component with a close button and a flow panel; 在这种情况下,我有一个带有关闭按钮和流面板的基本组件。 ( FlowLayoutPanel ) the idea being that components extending this add their controls to the flow panel and will have the close button functionality done for them. FlowLayoutPanel )的想法是,扩展此功能的组件将其控件添加到流面板,并将为其完成关闭按钮功能。

The problem is that I can't seem to persuade VS to add the components in the subclassed component to the flow panel; 问题在于,我似乎无法说服VS将子类化组件中的组件添加到流面板中。 this ends up with me having to do so in the code. 最终我不得不在代码中这样做。 Which is all well and good except that it won't show up in the designer view. 除了不会在设计器视图中显示之外,一切都很好。 If I add it to the partial class with the designer generated code then I can see the controls in the designer view laid out by the flow panel. 如果我使用设计器生成的代码将其添加到部分类中,则可以在设计器视图中看到由流程面板布置的控件。 But this just gets overwritten afterwards. 但这之后会被覆盖。

Visual Studio doesn't seem to let you dock controls in inherited panels - unless I'm doing something wrong? Visual Studio似乎不允许您将控件停靠在继承的面板中-除非我做错了什么? I did make sure that the base panel is publically visible in case this was the issue. 我确实确保基本面板是公开可见的,以防出现此问题。

-- -

An alternative might be some way to persuade the designer to execute/not overwrite my code in the designer class. 一种替代方法是说服设计人员执行/不覆盖设计人员类中的代码。

You need to make a ControlDesigner for your control and override the InternalControlDesigner and GetParentForComponent methods. 您需要为控件创建一个ControlDesigner ,并重写InternalControlDesignerGetParentForComponent方法。

For an example, open System.Windows.Forms.Design.SplitContainerDesigner (in System.Design.dll in Reflector. 例如,打开System.Windows.Forms.Design.SplitContainerDesigner (在Reflector的System.Design.dll中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM