Including Panels defined in another file  
Author Message
lagu2653





PostPosted: Visual C# General, Including Panels defined in another file Top

I'm developing a Compact Framework 2.0 Windows CE application. It has a number of panels stacked on top of each other and a menu to navigate between the different panels. To be able to design each panel in the GUI editor of VS2005 I have one form per panel + one form where I put it all together and stack all panels on top of each other. So every time I redesign a panel I have to:

1. delete all panels from the form where I put it all together
2. paste all new panels back in to the form where I put it all together
3. edit the designer file of the form where I put it all together to remove any lines where one panel is added
into another panel.
4. edit the designer file of the form where I put it all together to make each panel be added into the form where
I put it all together.

I tried to add lines in the designer file of the form where I put it all together to add the panels without pasting them into the form where I put it all together, but I got a "NULL reference exception".

Question: How would you add all of the panels, each defined in a separate file, into the the form where you put
it all together without having to manually paste them in and then edit the designer file

/Lars



Visual C#7  
 
 
MarcD





PostPosted: Visual C# General, Including Panels defined in another file Top

It sounds like you need to learn how to use UserControls. Once you do this the Controls are added to the toolbox for that project and you can drag and dropthem onto your form easily.
Project -> Add Item -> User Control

 
 
lagu2653





PostPosted: Visual C# General, Including Panels defined in another file Top

I don't want to drop them onto my form. Each panel occupies the entire window. (It's a substitute for a card layout manager (Java), which does not exist in C#.) I want to keep them in their own files and just add one or a few lines which imports that panel into the form at compile time. I don't want to see the panel in my form editor for the form where I put it all together. I want that form to be empty except for the menu which has to be there. But in the code there should be lines like this:

MyForm.add(Panel1);
MyForm.add(Panel2);
MyForm.add(Panel3);
MyForm.add(Panel4);
MyForm.add(Panel5);
MyForm.add(Panel6);
MyForm.add(Panel7);


 
 
sirjis





PostPosted: Visual C# General, Including Panels defined in another file Top

If the panels are simple, you could just have all the panels in the form stacked on top of each other in the designer. To edit one, select its name in the dropdown above the properties and click on the Bring To Front toolbar button.

UserControls would work great too though, as Marc said. Each control would have a separate designer, and once you have them added to the main form correctly, you wouldn't need to edit the form file at all to change the usercontrols. This is closer to what you trying to do right now, and I would recommend it especially if the panels are complicated. With this, you may need to create methods in the user controls to give access to the data contained in them.