Windows Develop Bookmark and Share   
 index > Windows Forms Designer > user control at design time: a big pain...
 

user control at design time: a big pain...

Hi All:

I have a user control consisting on a panel containing two groupbox controls. I enabled designtime for these groupbox controls, so in Design time, I can resize the controls as needed.

The problem is that, in Design time, each time I click on a groupbox, it hides behind the panel containing both groupbox controls. In order to have the groupbox visible, I need to shrink or movethe panel until the groupbox appears. There is no way to individually select the controls, or use SentToBack/BringToFront so I can show/hide the controls.

Ideally, the form should remain at the back, but it doesn't happen.

Any suggestion? Any idea about how can I handle the Z-order position?

Regards;

Gus

GusSabina  Wednesday, June 25, 2008 3:51 AM

Hi GusSabina,

Based on my experience, the BringToFront and SendToBack tool button will affect the control by change the adding order of the container control, and I don’t think it can affect the user control because the adding order of these controls are hard coded in the user control’s constructor. On possible way is that you expose a property to let the user change the value and call the BringToFront or SendToBack according to the value.

Code Snippet

[Designer(typeof(MyDesigner))]

public partial class UserControl7 : UserControl

{

public UserControl7()

{

InitializeComponent();

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public TextBox MyTextBox

{

get { return this.textBox1; }

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Button MyButton

{

get { return this.button1; }

}

bool textBoxOnTop = false;

public bool TextBoxOnTop

{

get { return textBoxOnTop; }

set

{

textBoxOnTop = value;

if (this.DesignMode)

{

if (value)

this.textBox1.BringToFront();

else

this.textBox1.SendToBack();

}

}

}

}

class MyDesigner : ControlDesigner

{

public override void Initialize(IComponent component)

{

base.Initialize(component);

UserControl7 uc = (UserControl7)component;

this.EnableDesignMode(uc.MyTextBox, "MyTextBox");

this.EnableDesignMode(uc.MyButton, "MyButton");

}

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Tuesday, July 01, 2008 11:29 AM

Hi:

I have a user control containing two controls. I enable design time for those controls so the user can move/resize them.

The problem is that BringToFront() / SentToBack() options are not available for these controls. How can I enable these options?

Regards;

Gus

GusSabina  Wednesday, June 25, 2008 6:30 PM

I think you can access the individual controls from the Properties window.

At the top of that window is a Dropdown box.

If you search in that box for the control that you wish to select you should be able to access it that way.

hth

tattoo

tattoo  Thursday, June 26, 2008 6:29 AM

Hi:

The problem is that is a "user control", so there is some encapsulation and not all members and methods are accessible from the winform where the user control is used. In the properties window, some controls contained in the user control appear because I use the

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

However, they don't appear in the DropDown box of the Properties window. In this last, only the Winform and the usaer control appear, so I can select the complete usercontrol and not each sub-contro individually.

Just for now, I'm using

if (DesignMode == true)

{

control1.BringToFront();

}

in the Load event of the user control, so each time the user control is loaded this control appears (this control was the smallest insize, and so the most difficult to select when it is hidden). When it is hidden aggain, closing and re-opening the WinForm (re-loading the user control) it appears again. This works just for now.

While I was testing many things, at some point, the SentToBack()/BringToFront() options appear in the menu...But after that, I never saw these options again.

Regards;

Gus

GusSabina  Thursday, June 26, 2008 2:57 PM

Hi GusSabina,

Based on my experience, the BringToFront and SendToBack tool button will affect the control by change the adding order of the container control, and I don’t think it can affect the user control because the adding order of these controls are hard coded in the user control’s constructor. On possible way is that you expose a property to let the user change the value and call the BringToFront or SendToBack according to the value.

Code Snippet

[Designer(typeof(MyDesigner))]

public partial class UserControl7 : UserControl

{

public UserControl7()

{

InitializeComponent();

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public TextBox MyTextBox

{

get { return this.textBox1; }

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Button MyButton

{

get { return this.button1; }

}

bool textBoxOnTop = false;

public bool TextBoxOnTop

{

get { return textBoxOnTop; }

set

{

textBoxOnTop = value;

if (this.DesignMode)

{

if (value)

this.textBox1.BringToFront();

else

this.textBox1.SendToBack();

}

}

}

}

class MyDesigner : ControlDesigner

{

public override void Initialize(IComponent component)

{

base.Initialize(component);

UserControl7 uc = (UserControl7)component;

this.EnableDesignMode(uc.MyTextBox, "MyTextBox");

this.EnableDesignMode(uc.MyButton, "MyButton");

}

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Tuesday, July 01, 2008 11:29 AM

You can use google to search for other answers

Custom Search

More Threads

• Overlaying a Windows Form on a Direct3d window
• CollectionEditors & ComponentDesigners
• how to implement ruler line in vb.net
• How to manage menu items when a user login?
• TabControl / TabPages and control events when edit via PropertyGrid
• Assign a Char* to Label
• How to use "Design Time" CollectionEditor for List <> type property of a User Control?
• Imports Data from XLS file to DataGridView VB 2005
• Newbie Developer Question
• Win32 Designer Question.