继承表单上的控件被锁定,可以撤消吗? [英] Controls on inherited form are locked, can it be undone?

查看:25
本文介绍了继承表单上的控件被锁定,可以撤消吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置:

我创建了一个 Form,我希望将它作为我继承其他表单的基础.这个基本表单充当各种模板",但它也提供了大量与结构相关的功能,以及所有提供的控件的相互关系.

I have created a Form that I wish to have serve as the base from which I will inherit other forms. This base form serves as a "template" of sorts, but it also provides a good deal of functionality related to the structure, as well as the interrelation of all of the controls provided.

以下图像的入门... 顶部信息彩色栏是从 ToolStrip 继承的自定义控件.底部的条带是另一个自定义,再次继承自 ToolStrip.左边的白色块是一个 TreeView,右边的块是一个 TabControl(已经从中删除了所有 TabPages...我打算让这些以继承的形式添加).

A primer for the images that follow... The top info-colored bar is a custom control inherited from ToolStrip. The bottom strip is another custom, again inherited from ToolStrip. The left white block is a TreeView and the right block is a TabControl (having deleted all TabPages from it...I intend for these to be added in the inherited forms).

设计器中基本表单的图像:

设计器中继承形式的图像:

很明显,唯一的区别是当我打开继承的表单时,我会在每个控件上叠加一个小框图标,当我单击它们时,我收到挂锁提示我无法编辑.

Clearly, the only difference is that when I open the inherited form, I get a little box icon superimposed over each control, and when I click them, I get the padlock telling me I cannot edit.

问题:

继承窗体上的所有控件都被锁定.我研究了视觉继承,据我所知,我没有使用任何明确不支持它的控件,如 此链接 表明有.在这个问答中,汉斯建议更改这些控件上的修饰符,我有完毕.事实上,我尝试了 PublicProtected,但都没有好的结果.

All controls on the inherited form are locked. I have researched the issue of visual inheritance, and as far as I can tell, I'm not using any controls that expressly do not support it, as this link suggests there are. In this Q&A, Hans suggests changing the modifier on those controls, which I have done. In fact, I tried both Public and Protected, all to no good result.

我被难住了.

推荐答案

这是设计器中的技术限制,它特定于您正在使用的 SplitContainer 控件.还有一些其他的.麻烦的是 ISupportInitialize 接口.

This is a technical restriction in the designer, it is specific to the SplitContainer control you are using. And some other ones. The trouble-maker is the ISupportInitialize interface.

当控件无法以任意顺序分配控件的属性时,它们会使用此接口.设计器在看到控件实现此接口时提供帮助,它在开始分配属性时调用 BeginInit() 方法,在完成时调用 EndInit() 方法.控件使用这些方法来延迟属性分配的副作用,EndInit() 方法使它们有效.对于 SplitContainer 很重要,面板的最小尺寸也会影响拆分器的位置.

Controls use this interface when they can't afford the properties of the control to be assigned in an arbitrary order. The designer helps when it sees that the control implements this interface, it calls the BeginInit() method when it starts assigning properties, EndInit() when it is done. The control uses these methods to delay the side-effect of property assignments, the EndInit() method makes them effective. Important for SplitContainer, the minimum sizes of the panels also affect the splitter position.

也许你可以看到问题,基础表单类中的 InitializeComponent() 方法已经调用了 ISupportInitialize.EndInit().因此,在派生形式类中再次修改属性不太可能结果很好.设计者通过锁定来保护控件不受此影响.

Perhaps you can see the rub, the InitializeComponent() method in the base form class has already called ISupportInitialize.EndInit(). So modifying properties again in the derived form class is unlikely to turn out well. The designer protects the control from this by locking it.

非常不方便,没有简单的解决方法.如果在派生表单类中修改 SplitContainer 是一个硬性要求,那么您将不得不放弃继承它或在派生类构造函数中手动编写代码.

Very inconvenient, there is no simple workaround. If modifying the SplitContainer in the derived form class is a hard requirement then you'll have to give up on inheriting it or write the code by hand in the derived class constructor.

这篇关于继承表单上的控件被锁定,可以撤消吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆