Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Multiple views for a single form (or UserControl)
 

Multiple views for a single form (or UserControl)

I have a UserControl that manages a lot of editable information (using sub-controls, like text-boxes). Now I need to make a version of this control that has a different layout (from horizontal to vertical). Right now I copy the entire control (code and all) to a new control, and use Windows Forms Designer to re-arrange all the subcontrols. This isn't so hard to maintain (just copy all the code from one control to the other views whenever a change is made), but it's very inelegant. Is there a better way to do this?

If not, I can think of two ways to improve the Windows Forms Designer:

1) Under the user control, have multiple "UserControl.Designer.cs" files that can be editited by the designer. Each file could define a new type, or maybe there's a better way to merge the different views with the code in the "UserControl.cs" file dynamically.

2) A better solution might be to allow the designer to move subcontrols within a control on the form. For instance I put a copy of my UserControl on a form, and then right click "Edit sub-control properties". The designer allows me to change the locations and properties of the sub-controls so I can easily make the control fit on the form (make some sub-controls bigger/smaller/invisible, etc.). On a different form I put my control down, and then re-arrange the subcontrols to fit vertically.

-Jeremy
JeremyAtGosub  Monday, September 28, 2009 3:27 AM

Hi,

 

Base on my understanding, one usercontrol can only have one designer.cs. And the sub-controls cannot be moved and resized on usercontrol when usercontrol is dragged to the form.

You can expose sub-controls’ size and location, then user can modify sub control layout.

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, October 05, 2009 3:01 AM
Thank you for the response Ling,

That kind of works, but not well enough for me to switch from the method I'm currently using.  When I expose the sub-control, like this:

        public TextBox MyText
        {
            get { return myText; }
            set { myText = value; }
        }

The designer will now let me manually change the properties, but will not let me visually reposition them.  Sure, I can change the Location and Size manually, but that's not why I'm using the forms designer in the first place.

It would be great if the the designer could see the above property, and then let me change the layout visually.  Is there a way I can request a feature like that?

-Jeremy

JeremyAtGosub  Wednesday, October 07, 2009 3:06 AM

You can use google to search for other answers

Custom Search

More Threads

• How to make form movable but prevent maximize
• how to chnage cusor for Dynamic created Context menu
• This forum has migrated successfully on December 10, 2008
• how to use the vertical scroll bar
• Need Help with Panels
• Add a Windows Form file into a project
• Designer will not display form with a bindingsource
• DesignSurface with Tabbed format
• datagridview help
• Bug - Getting the SelectedItem in ListBox