Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Windows Form called Form 3. It has a side panel and a child-form panel.

The side panel has an Exam Scheduler button which loads Form 5 on to the child-form panel.

Code example,
C#
private void profile_Click(object sender, EventArgs e)
    {
        openChildForm(new Form5());
    }

    private Form activeform = null;

    private void openChildForm(Form childForm)
    {
        if (activeform != null)
        {
            activeform.Close();
        }
        activeform = childForm;
        childForm.TopLevel = false;
        childForm.FormBorderStyle = FormBorderStyle.None;
        childForm.Dock = DockStyle.Fill;
        childFormPanel.Controls.Add(childForm);
        childFormPanel.Tag = childForm;
        childForm.BringToFront();
        childForm.Show();
    }

There's a button in Form 5. I want to learn how to code this button, so it could load another form on to the child-form panel in Form 3.

Is there a better way to achieve this other than this way?

Could someone please suggest me a YouTube video or any other site that teaches how to do this

What I have tried:

I learned to the code this form through a YouTube video. But it only explains about how to load a form on to a panel.

I don't know how to code the button in Form 5 in order to satisfy my requirement.

Please help!
Posted
Updated 30-Apr-20 7:43am
Comments
RmcbainTheThird 30-Apr-20 13:15pm    
I don't want to be a 'get off my lawn' kinda guy, but have you thought about buying a book and using that to learn how to write software?
Kushani Devendra 30-Apr-20 13:19pm    
I just want to know the code to my requirement for the time being.
BillWoodruff 2-May-20 8:08am    
Why do you use multiple Forms here ?
Kushani Devendra 3-May-20 13:13pm    
Is there anything else I can use other than forms?
BillWoodruff 3-May-20 15:11pm    
As Rick Zeeland suggests in his answer, here, use a UserControl.

1 solution

It is not a good idea to put a form into a panel, it's better to create a usercontrol and put that into a panel.
See: How to load UserControl into panel?[^]
And: Creating a Simple User Control and Adding it to the Toolbox[^]
 
Share this answer
 
v2
Comments
BillWoodruff 2-May-20 8:08am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900