user3530547
user3530547

Reputation: 41

C# Hide parent form when child form is active

I have a easy homework assignment, I have to make a parent form in C# that will have three text boxes where I enter data into each box, then I hit a process button and it will send that data to a child form displaying the same information in the three boxes in the child form. I have the program working, however part of the assignment is that when the child form is active the parent form is to be hidden and then when I close the child form the parent returns. I am not sure how do to this? Any help?

Thanks.

Here is my code for the parent form...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chapter_15_Ex.Child_Parent_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void processToolStripMenuItem_Click(object sender, EventArgs e)
        {


            string name;
            string address;
            int ccnum;

            name = Convert.ToString(txtName.Text);
            address = Convert.ToString(txtAddress.Text);
            ccnum = Convert.ToInt32(txtCreditCard.Text);

            Form2 childform = new Form2();
            //childform.MdiParent = Form1;
            childform.Show();

            childform.txtOutputName.Text = name;
            childform.txtOutputAddress.Text = address;
            childform.txtOutputCreditCard.Text = Convert.ToString(ccnum);          



        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Upvotes: 0

Views: 5076

Answers (1)

Grant Winney
Grant Winney

Reputation: 66439

Since this is for homework, I'll explain it instead of providing the code.

Here are the steps:

  1. Create an instance of Form2 (you already have that)

  2. Hide the current form (there's a method you can call on this. )

  3. Show Form2, but then stop the current form until Form2 closes - hint: there's a different call than childForm.Show(), but it's named similarly, and it prevents the code in Form1 from continuing until the child form is closed.

  4. Show the current form again (different method on this. ; opposite of the one from step 2)

Upvotes: 6

Related Questions