Tuesday, October 13, 2009

How to Dispose a Form in C# Without Closing the Application

in program.cs file replace the following code

      Application.Run(new Form1());

with, an instance of your start-up form, such as

   Form1 frm1 = new Form1();
   frm1.Show();
   Application.Run();
*** now you can dispose the form without closing the application
-------------------------------------

from time to time, you will be needing these codes:

   Application.Exit(); <- to close the whole application

   frm1.Close(); <- to close your current form window
   frm1.Dispose(); <- to free memory resources, when form is shown modally. ^_^
-------------------------------------
***good luck***

2 comments:

  1. cha..grabe nakalimot najud ko anang mga codes. grabe... :(

    ReplyDelete
  2. hi ye! lage..maning-tiil na jud ni ba! ^_^
    oks ra na ye! dli man pud kani imo gipili na work.hehehe.stress na kau ako student...pati pud ako!.hehehe.kay ngano ngteacher!

    ReplyDelete