Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Trouble creating a custom user control to act as a container with a specific content panel
 

Trouble creating a custom user control to act as a container with a specific content panel

I havea user control that I created, it has a header panel, a content panel, and a progress bar. When I drop this user control into a form, I would want to have the user control's content panel act as the container, this means if I dock my contents in this user control, it would only dock to the content panel, and not the whole control.

This control is similar to the TabControl or GroupBox, in that there is a panel for the content, but there's also other parts such as the Tabs or the Text.

I've done some research on this, so far I've found that if you put this attribute on my user control class, it would make the control a parent container:

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]

However, this does not solve the Docking issue, nor does it display properly when I use the user control -whatever content shown in the user control gets hidden at run-time.

Please let me know if you have a solution! Any helpwould beappreciated.

Ann Li  Friday, January 09, 2009 2:57 PM
Hi Ann Li,

Based on my understanding, you'd like to dock the content in one panel of your usercontrol, right?

If so, we can use create a custom controldesigner and enable the design mode of the panel inside the UserControl by invoking EnableDesignMode method. Set the boardStyle of the Panel to FixedSingle so that it will give you a clue of the location of the inside panel.

Please refer to this resolved thread, there is a code sample demonstrating you how to achieve that.

If you have any further problem, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Tuesday, January 13, 2009 12:44 PM
Hi AnnLi,

Please try to setDesignerSerializationVisibilityAttribute to Content for the panel so that the designer can serialize code for this panel. You can refer to this page for more about DesignerSerializationVisiblity.

Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byAnn Li Friday, January 16, 2009 9:01 PM
  •  
Bruce.Zhou  Friday, January 16, 2009 6:12 PM
Hi Ann Li,

Based on my understanding, you'd like to dock the content in one panel of your usercontrol, right?

If so, we can use create a custom controldesigner and enable the design mode of the panel inside the UserControl by invoking EnableDesignMode method. Set the boardStyle of the Panel to FixedSingle so that it will give you a clue of the location of the inside panel.

Please refer to this resolved thread, there is a code sample demonstrating you how to achieve that.

If you have any further problem, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Tuesday, January 13, 2009 12:44 PM
Hi Bruce,

This was exactly what I wanted, thanks so much!

This works perfectly at design time, that is, when I dock the content to the user control, it docks to the inner panel.

I'm still experiencing the issue of the content disappearing at run-time though. I tried to make the content "bring to front" and set the backcolour to a solid colour,I also tried different controls(a radiobutton disappears just as well as a panel) and docking values (Dock to Top or Fill).

Is there something I'm missing?

Thanks,
Ann
Ann Li  Friday, January 16, 2009 4:41 PM
Hi AnnLi,

Please try to setDesignerSerializationVisibilityAttribute to Content for the panel so that the designer can serialize code for this panel. You can refer to this page for more about DesignerSerializationVisiblity.

Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byAnn Li Friday, January 16, 2009 9:01 PM
  •  
Bruce.Zhou  Friday, January 16, 2009 6:12 PM
Thanks you SO MUCH Bruce!! I really appreciate it.
Ann Li  Friday, January 16, 2009 9:02 PM
I heve tried the code posted above and shows that the controls are actually added to the panel container, but i cant see them at run time. Any idea of what could be happening.
hajrodriguez  Tuesday, June 16, 2009 9:52 PM

Please take a look at my second post which is marked as answer. You can apply DesignerSerializationVisiblity attribute to the panel.

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel InnerPanel{

get { return innerPanel; }

set { innerPanel = value; }

}
Add the code which is in bold font.

Best regards,
Bruce Zhou


Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Wednesday, June 17, 2009 12:47 AM

You can use google to search for other answers

Custom Search

More Threads

• How to change ParentControlDesigner behavior
• Temporarily disable an event handler at runtime
• Transparent Panel in Design Time
• Using Web Form Designer in a Windows Form Application
• progress bar in windows application till the query executes
• System.Windows.Forms.Message - Doubt
• Specifying a DesignerLoader?
• Usercontrol & properties at run time
• Visual Studio is not adding a .resx with a form...
• When/Where should I instantiate the control when placing on the designer