Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Change parent at design time
 

Change parent at design time

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
cold80  Thursday, October 09, 2008 5:24 PM

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 suggestyouwrite some code to achieve that goal.

Best Regards,

Bruce Zhou.

Bruce.Zhou  Wednesday, October 15, 2008 10:03 AM

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 suggestyouwrite some code to achieve that goal.

Best Regards,

Bruce Zhou.

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; }
}

psmartt  Wednesday, October 15, 2008 11:05 PM

You can use google to search for other answers

Custom Search

More Threads

• acces property in another class
• how to handle Events of user control?
• Serializing components to .resx
• Pass parameters from designer to autogenerated controls
• How to set an event when the desing-time is initalizing?
• Deleting left over controls
• Multiple views for a single form (or UserControl)
• help with vs2005 crashing because of my code
• Raising events from extern form
• adding data to comboBox