locked
Change parent at design time RRS feed

  • Question

  • Sorry if my question could appear silly, but I can't really find a solution. I'm developing with C# on VS 2008 SP1. The problem is that in the same form I have more than one panel, and each panel has some child controls. Now, when I move around the controls VS automatically set the parent of the controls to the panel I drop them into. Actually it's very difficult to make VS behave in the way I would like to, so I was wondering if it's possible to set the parent of a control without changing the code behind of the form. I mean, is there some function in VS I dont know about that allows to set the parent container of a control or something like that?

    Thank you for your help

    cold
    Thursday, October 9, 2008 5:24 PM

Answers

  • Hi cold80,

     

    I think there is no built function for Visual Studio designer to do as you want without any code. Your requirement may be rare. However, if you indeed need it, I suggest you write some code to achieve that goal.

     

    Best Regards,

    Bruce Zhou.

     

    Wednesday, October 15, 2008 10:03 AM

All replies

  • Hi cold80,

     

    I think there is no built function for Visual Studio designer to do as you want without any code. Your requirement may be rare. However, if you indeed need it, I suggest you write some code to achieve that goal.

     

    Best Regards,

    Bruce Zhou.

     

    Wednesday, October 15, 2008 10:03 AM
  • I have not tried this, but you should be able to create a property in the class and mark it with the browsable attribute.  In the property you set  the real parent.  By using the Browsable Attribute, you will be able to see the property in the properties window in the designer. You will then be able to set the parent in the designer.

    vb.net ...

    Imports System.ComponentModel

        <Browsable(True)> _
        Public Property ParentWrapper() As Control
            Get
                Return Me.Parent
            End Get
            Set(ByVal value As Control)
                Me.Parent = value
            End Set
        End Property


    C#
    using System.ComponentModel;

    [Browsable(true)]
    public Control ParentWrapper
    {
        get { return this.Parent(); }
        set { this.Parent() = value; }
    }

    Wednesday, October 15, 2008 11:05 PM