<p>I have a need to close a parent form from within child form from a Windows application. What would be the best way to do this?</p>

[{'answer_id': 40970, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 3, 'selected': True, 'text': "<p>When you close form in WinForms it disposes all of it's children. So it's not a good idea. You need to do it asynchronously, for example you can send a message to parent form.</p>\n"}, {'answer_id': 40971, 'author': 'dguaraglia', 'author_id': 2384, 'author_profile': 'https://Stackoverflow.com/users/2384', 'pm_score': 0, 'selected': False, 'text': "<p>The Form class doesn't provide any kind of reference to the 'parent' Form, so there's no direct way to access the parent (unless it happens to be the MDI parent as well, in which case you could access it through the MDIParent property). You'd have to pass a reference to the parent in the constructor of the child, or a property and then remember to set it, and then use that reference to force the parent to close.</p>\n"}, {'answer_id': 41261, 'author': 'D2VIANT', 'author_id': 4365, 'author_profile': 'https://Stackoverflow.com/users/4365', 'pm_score': 0, 'selected': False, 'text': "<p>Perhaps consider having the parent subscribe to an event on the child, and the child can fire that event whenever it wants to close the parent. The parent can then handle it's own closing (along with the child's).</p>\n"}, {'answer_id': 41274, 'author': 'chrissie1', 'author_id': 2936, 'author_profile': 'https://Stackoverflow.com/users/2936', 'pm_score': 0, 'selected': False, 'text': '<p>You are clearly noo using the correct way to open and close forms. If you use any form of MVC or MVP this problem would not arise. </p>\n\n<p>So use a form of MVP or MVC to solve this problem.</p>\n'}, {'answer_id': 41579, 'author': 'Ed Schwehm', 'author_id': 1206, 'author_profile': 'https://Stackoverflow.com/users/1206', 'pm_score': 0, 'selected': False, 'text': "<p>I agree with davidg; you can add a reference to the parent form to the child form's constructor, and then close the parent form as you need:</p>\n\n<pre><code>private Form pForm;\npublic ChildForm(ref Form parentForm)\n{\n    pForm = parentForm;\n}\n\nprivate closeParent()\n{\n    if (this.pForm != null)\n        this.pForm.Close();\n    this.pForm = null;\n}\n</code></pre>\n"}, {'answer_id': 42107, 'author': 'Jason Von Ruden', 'author_id': 2062, 'author_profile': 'https://Stackoverflow.com/users/2062', 'pm_score': 3, 'selected': False, 'text': '<p>I ran across this blog entry that looks like it will work and it uses the Event Handler concept from D2VIANT Answer</p>\n\n<p><a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=125" rel="noreferrer">http://www.dotnetcurry.com/ShowArticle.aspx?ID=125</a></p>\n\n<p>Summary:\nStep 1: Create a new Windows application. Open Visual Studio 2005 or 2008. Go to File > New > Project > Choose Visual Basic or Visual C# in the ‘Project Types’ > Windows Application. Give the project a name and location > OK.</p>\n\n<p>Step 2: Add a n\new form to the project. Right click the project > Add > Windows Forms > Form2.cs > Add.</p>\n\n<p>Step 3: Now in the Form1, drag and drop a button ‘btnOpenForm’ and double click it to generate an event handler. Write the following code in it. Also add the frm2_FormClosed event handler as shown below:</p>\n\n<pre><code>    private void btnOpenForm_Click(object sender, EventArgs e)\n    {\n        Form2 frm2 = new Form2();\n        frm2.FormClosed += new FormClosedEventHandler(frm2_FormClosed);\n        frm2.Show();\n        this.Hide();\n    }\n\n\n    private void frm2_FormClosed(object sender, FormClosedEventArgs e)\n    {\n        this.Close();\n    }\n</code></pre>\n'}, {'answer_id': 45595945, 'author': 'Keyur Sureliya', 'author_id': 4454558, 'author_profile': 'https://Stackoverflow.com/users/4454558', 'pm_score': 0, 'selected': False, 'text': '<p>There\'s a very easy solution to that.</p>\n\n<p>Problem (To be sure) : Starts App(Main Form) > Open Child Form of Main Form VIA Button or Any Event > Closes (Main Form) But Child Form also Closes.</p>\n\n<p>Solution :</p>\n\n<blockquote>\n  <p>Use : <code>Process.Start("Your_App\'s_EXE_Full_Path.exe");</code></p>\n</blockquote>\n\n<p>Example : Try this to get full path:</p>\n\n<blockquote>\n  <ol>\n  <li><p><code>string FullPath = Environment.CurrentDirectory + "\\\\YourAppName.exe";</code></p></li>\n  <li><p><code>Process.Start(FullPath);</code>.</p></li>\n  <li><p><code>this.Close();</code></p>\n  \n  <ul>\n  <li>this way you\'ll get to keep every form you want to keep open.</li>\n  </ul></li>\n  </ol>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/40962', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2062/']