WinForms ToolStrip not available in visual inheritence
Lets say I have FormChild inheriting Fo开发者_StackOverflow中文版rmParent. 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?
Well you can manually edit FormChild.Designer.cs file. There you can access inherited toolstrip.
Edit:
Add this class:
//System.Design.dll required [Designer(typeof(System.Windows.Forms.Design.ControlDesigner))] public class InheritableToolStrip : ToolStrip { }
Compile project
- Use InheritableToolStrip from toolbox to add to FormParent.
- Change Modifier property to protected.
- Add items to inherited toolstrip in FormChild.
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 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
You can pass the toolstrip to the child form like this.
public partial class ChildForm : Form
{
private readonly ToolStrip parentToolStrip;
public ChildForm(ToolStrip strip)
{
parentToolStrip = strip;
}
}
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.
精彩评论