在什么地方指定父控件?
我是直接在属性编辑器上对ToolBar进行增加ToolButton的。

解决方案 »

  1.   

    看看DesignerSerializationVisibilityAttribute的帮助
      

  2.   

    Jim3具体应该怎么用?msdn上面写的不是很明确。
      

  3.   

    public class MyUserControl: System.Windows.Forms.UserControl
    {
        private System.Windows.Forms.ToolBar toolBar1;
        public ToolBar TBar
        {
           get{return new toolBar1;}
           set{toolBar1 = value;} 
        }
    }
      

  4.   

    public ToolBar TBar
    {
    get{return toolBar1;}
    //set{toolBar1 = value;} 不需要set属性。
    }
      

  5.   

    lonestar5555和jimh你们说的都不对。
    jim3说的应该是对的。。但是我不知道具体怎么使用。
      

  6.   

    晕我的代码都贴出来了啊。。就是那些。。那是用户控件的代码,其他的就是把用户控件放到窗体上。然后通过属性编辑器对这个用户控件上的ToolBar进行增加ToolBarButton。
    你试一下就知道结果了。
      

  7.   

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public ToolBar.ToolBarButtonCollection Buttons
    {
    get{return toolBar1.Buttons;}
    }
    我现在测试出。在UserControl里面再增加一个这样的属性。就能达到我的要求了。
    加到窗体上以后的生成的代码是这样的
    this.myUserControl = new myUserControl();
    this.toolBarButton19 = new System.Windows.Forms.ToolBarButton();
    this.toolBarButton20 = new System.Windows.Forms.ToolBarButton();
    this.myUserControl.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {this.toolBarButton19, this.toolBarButton20});
    已经达到了我要的结果。
    但是。最后一条语句不理想。我觉得应该是
    this.myUserControl.TBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {this.toolBarButton19, this.toolBarButton20});
    有什么办法搞定?
      

  8.   

    有时并不能完全依赖IDE的设计时功能,这个功能是有限的.
    如果不是一定要这么做,就换一个思路吧.
      

  9.   

    try
    http://www.csdn.net/develop/Read_Article.asp?id=24936
    http://www.csdn.net/develop/Read_Article.asp?id=24937
    http://www.csdn.net/develop/Read_Article.asp?id=24938
    http://www.csdn.net/develop/Read_Article.asp?id=24939