Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all!

This is my issue :

- I have 3 forms :
Form fParent
Form fChild
Form OpenForm

I want that When I click a button on Form fChild, it shows Form OpenForm and hide Form fParentand Form fChild.
How can I do that? Please help me.
Thanks and best regards!
Posted
Comments
Nayan Ambaliya 14-Apr-15 0:04am    
There are two things. "Hide" and "Close" and both have different meanings.. Over the top, there are things like MODAL and NON-MODAL dialogs.

What do you really want to achieve? and what have you tried so far..
Sergey Alexandrovich Kryukov 14-Apr-15 2:48am    
Nayan is right.
Besides, there are no parent and child form. Most likely, you concern is about closing non-main form. My question is: do you want to exit the application when this form is closed or not?
—SA
BillWoodruff 14-Apr-15 7:45am    
You need to clarify your question: which Form is the "Main Form" ? Are you actually making a Form the "child" of another Form by setting the Form's Parent property ?

Do you want to show any of the Forms modally ? And, so on.

1 solution

Main Form

C#
namespace cp5
{
    public delegate void dHide(bool hide);
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        void Button1Click(object sender, EventArgs e)
        {
            Form1 fm1=new Form1();
            fm1.delfunc+=hideform;
            fm1.Show();
        }
        void hideform(bool hide)
        {
            if (hide) this.Hide();
            else this.Show();
        }
    }
}



and child form to hide/show main form:

C#
namespace cp5
{
	public partial class Form1 : Form
	{
		public dHide delfunc=null;
		public Form1()
		{
			InitializeComponent();
		}
		void Button1Click(object sender, EventArgs e)
		{
			delfunc(true);
		}
		void Button2Click(object sender, EventArgs e)
		{
			delfunc(false);	
		}		
	}
}
 
Share this answer
 

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