C# windows form

C# source code for Close parent window when show the child form

Page 1 of 1

5 Replies - 2770 Views - Last Post: 15 September 2008 - 01:46 PM Rate Topic: -----

#1 sri_sai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-September 08

C# windows form

Post icon  Posted 13 September 2008 - 03:07 AM

if form1

it has buttton1
under button1 click

private void button1_Click(object sender, EventArgs e)
        {
           
            Form2 f = new Form2();
                     
            f.Show ();
           
            this.close()
  
         }


Is This A Good Question/Topic? 0
  • +

Replies To: C# windows form

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 39
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: C# windows form

Posted 13 September 2008 - 03:17 AM

Use this.hide()
Was This Post Helpful? 0
  • +
  • -

#3 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 41
  • View blog
  • Posts: 1,166
  • Joined: 23-June 08

Re: C# windows form

Posted 13 September 2008 - 03:50 PM

Try this
this.Parent.Dispose();



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: C# windows form

Posted 15 September 2008 - 05:27 AM

View Postgbertoli3, on 13 Sep, 2008 - 06:50 PM, said:

Try this
this.Parent.Dispose();



Hope this helps


if the Parent form is the startup form for the project, then this will exit the project completely.

to the original poster, if you are trying to close the startup form, then it will close the application. You will need to hide the startup form when moving to other forms. With any other form, you can use your code.
Was This Post Helpful? 0
  • +
  • -

#5 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 41
  • View blog
  • Posts: 1,166
  • Joined: 23-June 08

Re: C# windows form

Posted 15 September 2008 - 06:30 AM

Are saying he's using a MDI Parnent window?
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: C# windows form

Posted 15 September 2008 - 01:46 PM

View Postgbertoli3, on 15 Sep, 2008 - 09:30 AM, said:

Are saying he's using a MDI Parnent window?


no...I guess I should have used "startup form" instead of "parent form". If you close the startup form for a project, then the entire project closes.

This post has been edited by eclipsed4utoo: 15 September 2008 - 01:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1