Discussion:
Setting properties on hosted toolstrip control at design time
(too old to reply)
Mike
2009-07-30 20:48:25 UTC
Permalink
I created my own toolstrip control using ToolStripControlHost. When I
add this to a toolstrip, I want to adjust the properties of the hosted
control in the designer but they always get reset when I compile. Can
anyone tell me how to fix this? This should be similar to accessing
the panels in a SplitContainer control so I think it is possible.

Here is some *sample* code to illustrate the problem.

[ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip |
ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripHostExample : ToolStripControlHost
{
public TextBox MyControl
{
get { return (TextBox)Control; }
}

public ToolStripHostExample() : base(new TextBox())
{
}
}

Add it to a toolstrip and try to set the MyControl.ReadOnly attribute
to true in the designer. When you compile, the property will be reset
to false.
Mike
2009-07-31 14:01:57 UTC
Permalink
For anyone else struggling with a similar problem, I found the
solution by taking a closer look at the panels in theSplitContainer
control.

Adding the DesignerSerializationVisibility attribute to the MyControl
property in my sample code solves the problem. Here is the fixed
sample code...

[ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip |
ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripHostExample : ToolStripControlHost
{
[DesignerSerializationVisibility
(DesignerSerializationVisibility.Content)]
public TextBox MyControl
{
get { return (TextBox)Control; }
}

public ToolStripHostExample() : base(new TextBox())
{
}
}
Post by Mike
I created my own toolstrip control using ToolStripControlHost. When I
add this to a toolstrip, I want to adjust the properties of the hosted
control in the designer but they always get reset when I compile. Can
anyone tell me how to fix this? This should be similar to accessing
the panels in a SplitContainer control so I think it is possible.
Here is some *sample* code to illustrate the problem.
[ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip |
ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripHostExample : ToolStripControlHost
{
  public TextBox MyControl
  {
    get { return (TextBox)Control; }
  }
  public ToolStripHostExample() : base(new TextBox())
  {
  }
}
Add it to a toolstrip and try to set the MyControl.ReadOnly attribute
to true in the designer. When you compile, the property will be reset
to false.
Loading...