WinForms ToolStrip 在视觉继承中不可用
假设我有 FormChild 继承 FormParent。在父级中,顶部有一个工具提示。我想要的是在我的子表单中添加额外的元素,但控件始终处于锁定状态,尽管我已将修饰符设置为受保护。
我上网查了一下,看来这是一个众所周知的bug;但有人知道解决方法或其他什么吗?
Lets say I have FormChild inheriting FormParent. In parent, there is a toolstip at the top. What I want is in my child form to add extra elements, but the control is always locked, although I've set the modifiers to protected.
I've checked the Internet, it seems this is a well-known bug; but does anyone know a workaround or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那么您可以手动编辑 FormChild.Designer.cs 文件。在那里您可以访问继承的工具条。
编辑:
添加此类:
编译项目
并且您应该能够在设计器中设计控件。尝试了一下 - 似乎有效。
PS我使用VS2010,.NET v4
Well you can manually edit FormChild.Designer.cs file. There you can access inherited toolstrip.
Edit:
Add this class:
Compile project
and you should be able to design control in designer. Tried a bit - seems like it works.
P.s. Iam using VS2010, .NET v4
Microsoft 已锁定复杂控件的视觉继承,因为他们无法弄清楚如何以简单的方式管理继承树上的子项控件的设计器序列化。
一个简单的解决方法(达到相同的效果)是在子表单上放置一个不可见的工具条,并在加载时将其与基本表单工具条合并。
我开发了 MergableToolStrip 控件,您可以在此处免费使用
Microsoft have locked down Visual Inheritance for complex controls because they couldn't figure out how to manage the designer-serialization of child item controls over an inheritance tree in a simple way.
A simple workaround (which achieves the same effect) is to drop an invisible toolstrip on the sub-form and merge it with the base-forms toolstrip at load time.
I've developed MergableToolStrip controls you can use free of charge here
您可以像这样将工具条传递给子表单。
请注意,上面的代码语法可能是错误的,我知道控件名称比 ToolStrip 更长,我只是用作演示来向您展示概念。
You can pass the toolstrip to the child form like this.
Please note that the above code syntax may be wrong, I know the control name is longer then just ToolStrip, I just used as demo to show you the concept.