Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

How to close a form in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
thejamie - 21 Apr 2005 19:53 GMT
I'm trying to close a form in C#.  I have a vb background, so the question
may sound dumb.  In vb it is just me.close().  I've tried a bunch of ways to
close the form  but C# is acting pretty dumb also.  I can't find a way to
close it.  Here are some of the things I've tried:

        private void button1_Click(object sender, System.EventArgs e)
        {
//            Form1 frmI = new Form1();
//            DialogResult dr = frmI.ShowDialog();

            Form1.Quit();
//            this.Hide();

        }

The new form seems to recreate the form - that is a total nightmare.  Hide
doesn't end the program and Close just gets a message that says close is not
defined.
Signature

Regards,
Jamie

thejamie - 21 Apr 2005 20:04 GMT
Thanks... tried again with This.close(); and this time it worked.  Not sure
what was going on but thanks for the help.

> I'm trying to close a form in C#.  I have a vb background, so the question
> may sound dumb.  In vb it is just me.close().  I've tried a bunch of ways to
[quoted text clipped - 14 lines]
> doesn't end the program and Close just gets a message that says close is not
> defined.
Herfried K. Wagner [MVP] - 21 Apr 2005 20:10 GMT
"thejamie" <thejamie@discussions.microsoft.com> schrieb:
> Thanks... tried again with This.close(); and this time it worked.  Not
> sure
> what was going on

Note that C# is case-sensitive!

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

thejamie - 21 Apr 2005 20:15 GMT
Whoa... it isn't self correcting!  I'm glad you mentioned this.
Thanks again.

> "thejamie" <thejamie@discussions.microsoft.com> schrieb:
> > Thanks... tried again with This.close(); and this time it worked.  Not
> > sure
> > what was going on
>
> Note that C# is case-sensitive!
Herfried K. Wagner [MVP] - 21 Apr 2005 20:09 GMT
"thejamie" <thejamie@discussions.microsoft.com> schrieb:
> I'm trying to close a form in C#.  I have a vb background, so the question
> may sound dumb.  In vb it is just me.close().  I've tried a bunch of ways
[quoted text clipped - 16 lines]
> not
> defined.

Mhm...  'this.Close();' should work.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

rmacias - 21 Apr 2005 20:11 GMT
I'm assuming button1_Click() is an event handler for a button on the form
that you want to close.  So if you want to close the form, it would look like
this:

private void button1_Click(object sender, System.EventArgs e)
{
    this.close();
}

If this form is the entry point for your application, then the applicaton
will exit when the form is closed.  If this form is not the entry point to
your application, but want to close the application, you could use
Application.Exit(); to end your program.

> I'm trying to close a form in C#.  I have a vb background, so the question
> may sound dumb.  In vb it is just me.close().  I've tried a bunch of ways to
[quoted text clipped - 14 lines]
> doesn't end the program and Close just gets a message that says close is not
> defined.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.