Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Design/create panel control in a seperate class?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tinus - 15 Sep 2004 16:11 GMT
Hello,

I've got a question and have been looking for an answer several days now....
no luck yet :-(
Hopefully someone here can provide me with an answer.

This is what I want to do:
(Using Visual Studio 2003 and language C#)
I created a standard Windows Form with two normal buttons (btn1 and btn2).
When I press btn1 I what to display a panel (with labels, button, etc. in
it) in the main form. But when I press btn2 I what to display a different
panel (with labels, text, etc. in it) on the same location as the previous
one.

For now, I've done this placing the two panel over each other and calling
BringToFront() to display them. But what if I whant to design 5 panels which
all need to be placed on the same location and are the same size....?

The best solution for me would be creating a seperate class for each panel
(layout and code). But I also want to use the Visual Studio designer to
design the panels.

Can somebody here tell me if this is possible?

Thanks in advance!

Tinus
Sean J Donovan - 15 Sep 2004 16:16 GMT
> Hello,
>
[quoted text clipped - 23 lines]
>
> Tinus

Place a panel on the main form, use it as a place-holder.
Design all sub-panels separately, as UserControls (you could still
derive from Panel, but little point).
Just place the sub-panels within the place-holder panel (setting Dock.Fill).
Still use BringToFront to update the Z-order when required.

Voila.

Sean
Tinus - 15 Sep 2004 16:38 GMT
Thanks for your quick repley!

But how to I place the sub-panels in the place-holder panel?
Can you give me a code sample of how to do this (place the sub-panel in the
place-holder panel I mean)?

E.g. placeholderPanel is in frmMain.cs and subPanel is in ctlPanel.cs (which
is a UserControl)...
Now what code do I use in frmMain to display the subPanel which is defined
in ctlPanel.cs in the placeholderPanel?

Thanks again!

Tinus

> > Hello,
> >
[quoted text clipped - 33 lines]
>
> Sean
Sean J Donovan - 15 Sep 2004 17:03 GMT
OK, on your main-form, you'll have a panel

    private Panel _myPanel

Design your user-controls (eg. UserControl1), to add to the main on the
main-form, code (not design) the following in your button handler:

    // Instantiate the user control to display in the panel.
    UserControl1 uc = new UserControl1();

    // Set the user-control's dock-style to Fill .
    uc.Dock = DockStyle.Fill;

    // Add the control to your place-holder panel.
    _myPanel.Controls.Add( uc );

Obviously, you'll need to add logic to check to see whether you'd
already created the control.  You could record record the variable in
your form, or just iterate through the controls and look for it.  The
above might become:

    // Within the button handler . . .

    // Search the panel for a user-control of the desired type.
    // If a user-control of the right type was found, bump it to
    // the top of the Z-order.
    foreach( Control c in _myPanel.Controls )   
    {
        if ( c is UserControl1 )
        {
            c.BringToFront();
            return;
        }
    }

    // OK, the control of that type wasn't found, go create one.

    // IMPLEMENT THE CODE AT THE TOP.

There are a number of ways to do this, this just gives you an idea of
what to do.

Sean

> Thanks for your quick repley!
>
[quoted text clipped - 75 lines]
>>
>>Sean
Sean J Donovan - 15 Sep 2004 17:19 GMT
I guess the other option is to use the TabControl, which sounds kinda'
close to what you're trying to do.

> OK, on your main-form, you'll have a panel
>
[quoted text clipped - 122 lines]
>>>
>>> Sean
Tinus - 15 Sep 2004 17:35 GMT
Thanks a lot!

Tinues
> I guess the other option is to use the TabControl, which sounds kinda'
> close to what you're trying to do.
[quoted text clipped - 125 lines]
> >>>
> >>> Sean

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.