开发者

How can I inherit form and access controls from mother form?

开发者 https://www.devze.com 2023-01-03 12:39 出处:网络
I\'m in the middle of writing my project and I have this problem: I try to write a library and I want to use it in my application. In library I ha开发者_运维技巧ve a form with menu strip, tool bar, li

I'm in the middle of writing my project and I have this problem: I try to write a library and I want to use it in my application. In library I ha开发者_运维技巧ve a form with menu strip, tool bar, list view, tree view and etc. Everything in library is protected. In my application I have created the form which inherit form the library. I can change and add new functionality to list view and tree view using designer panel in VS 2008 but I don't have access to menu strip and tool bar, even though they are protected. Why is that so? I will be thankful for some advice.


That was done intentionally in designers for the MenuStrip and ToolStrip controls. The subject of this feedback article. You could write code instead of using the designer. Or consider merging strips after the InitializeComponent() call, tricky to get right. Your best bet is probably to avoid putting them on your base form.


I guess that the protected members are fields.
The PropertyGrid in visual studio designer shows only properties, try to expose the desired field as properties.
Additionally - I think the properties should be declared as public for the designer to show them in the properties window.


This is because of the limitations of Visual Inheritence. You need to implement a workaround to get it working. Basically, you can expose a control to derived classes, but you will lose designer support.

The DataGridView also has this problem, and it what my blog post talks about.

0

精彩评论

暂无评论...
验证码 换一张
取 消