Closed Thread
Results 1 to 4 of 4

Thread: C# opening/closing forms

  1. #1
    Psynic's Avatar
    Psynic is offline Learning Programmer
    Join Date
    May 2009
    Location
    Canada, AB
    Posts
    61
    Blog Entries
    1
    Rep Power
    11

    C# opening/closing forms

    Hey guys im making a basic notepad right now with beginner knowledge and right now i am using the file menu on my form to open an "About" form now i have it opening up and displaying properly using this code

    Code:
            public void aboutNotepadToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Form2 Form2 = new Form2();
                Form2.Show();
                
            }
    but the problem i am having is with my code to close the form right now i am trying this code for the close button on my second form.

    Code:
            private void button1_Click(object sender, EventArgs e)
            {
    
                Form2 Form2 = new Form2();
                Form2.Close();
            }
    this doesn't give me any errors. form2 simply does not close. i tried with just Form2.Close(); for my close button but it gives me an error before running.

    i figure it has something to do with me creating a new instance of form2 right before i close. i just cant figure out any other way to put the code so i don't get an error.

    Any Help would be appreciated, i think this is a pretty easy one anyway.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: C# opening/closing forms

    All you have to do is change
    Code:
    Form2.Close();
    to
    Code:
    this.Close();
    And it will close the form.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

  4. #3
    Psynic's Avatar
    Psynic is offline Learning Programmer
    Join Date
    May 2009
    Location
    Canada, AB
    Posts
    61
    Blog Entries
    1
    Rep Power
    11

    Re: C# opening/closing forms

    :O <3 thx lol was driving me crazy.

  5. #4
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: C# opening/closing forms

    Hehe no prob.
    Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
    Science is only an educated theory, which we cannot disprove.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 02-03-2009, 10:39 AM
  2. Form Closing
    By AlexanderM in forum C# Programming
    Replies: 1
    Last Post: 03-31-2008, 09:42 AM
  3. Closing Ports! - Help
    By travy92 in forum Visual Basic Programming
    Replies: 20
    Last Post: 09-17-2007, 04:30 PM
  4. Closing Form without gap
    By NeedHelp in forum HTML Programming
    Replies: 1
    Last Post: 02-15-2007, 02:14 PM
  5. closing the cd rom
    By chinni in forum C# Programming
    Replies: 2
    Last Post: 10-16-2006, 02:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts