CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Windows Form

  1. #1
    Join Date
    Apr 2009
    Posts
    5

    Windows Form

    Hi Every one

    I trying to put windows form into an other windows form
    or put a usercontrol into a panel

    do someone know how to do this

    thx

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Windows Form

    Welcome to the Forum
    Your question is little confusing. If you want to make one form parent and the other child, you will have to use MDI Form. There is a property in the Windows Form that sets it as MDIForm. Once that is done, you then need to set the second forms MDIParent property to the first form.

  3. #3
    Join Date
    Apr 2009
    Posts
    5

    Re: Windows Form

    Thx for your reply

    Ok i confused my self with your explabation but I will explan more what I want.

    I want to make a application with different panel with visual studio.
    I know I can make panel and hide them or show them with my menu but I if there is a way that I can change the object in the panel like windows for or user control that will be the best because I will have all my interface design separatly and not in the same form

    I don't know if I explained it well
    Sorry if not

    Thx

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Windows Form

    To answer your question of whether you can put a User Control in the panel, yes you can. You can create a user control that will hold all your UI elements and then host it on to a Panel or the Form directly.

    In Visual Studio, just select project menu and then click User Control.

  5. #5
    Join Date
    Apr 2009
    Posts
    5

    Re: Windows Form

    Ok but how can I host the user control into a panel

    He there a conde line easy to put the user control in a panel

    thx

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Windows Form

    A user control is just like any other control you find on the Toolbox in Visual Studio. Like you put a text box inside a panel, same way you will put a User Control inside a panel.

  7. #7
    Join Date
    Apr 2009
    Posts
    5

    Re: Windows Form

    Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??

    Thx for help it's really appreciate

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Windows Form

    Quote Originally Posted by staclite View Post
    Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??

    Thx for help it's really appreciate
    I don't quite understand what you are trying to do.

    A user control is just like any other control and you can use it just like any other control.

  9. #9
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Windows Form

    Assuming you have 2 UserControls in your project. The following will switch out a Container's child control with a new one each time a button is clicked.

    Code:
    using System;
    using System.Windows.Forms;
    
    namespace DynamicUserControls
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            int mCurControl = 0;
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.groupBox1.Controls.Clear();
                switch (mCurControl)
                {
                    case 0:
                    case 2:
                        this.groupBox1.Controls.Add(new Control1());
                        mCurControl = 1;
                        break;
                    case 1:
                        this.groupBox1.Controls.Add(new Control2());
                        mCurControl = 2;
                        break;
                }
            }
        }
    }

  10. #10
    Join Date
    Apr 2009
    Posts
    5

    Thumbs up Re: Windows Form

    Thank you so much Mariocatch this make exactly what I wanted to do

  11. #11
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Windows Form

    Quote Originally Posted by staclite View Post
    Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??

    Thx for help it's really appreciate
    The standard way to do this would be to use different Usercontrols and one and the same interface for the data for each usercontrol. Use a Bulider pattern for doing this. A Factory can be used to create and switch between which Usercontrol is built and is shown on screen. As you are using the same interface for all of the usercontrols which should able to be presented its easily to add / read data to / from that controls.
    In fact I dont know whats your usercontrol contains. ( Dataaccess, database connection ...) The way already shown by mariocatch is a simple beginning if you have a simple situation. The patterns I mentioned are able to handle more complex situations too. If you have a very complex datahandling and different Usercontrols and you want to have an easy to maintainable code then google for Bridge pattern too.
    Last edited by JonnyPoet; April 13th, 2009 at 11:06 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured