unload form/dialog

Hello,
I am a newbie to C# and Visual Studio..and have a question ;))

Double clicking a form you automatically go into the load() event (alternatively using the forms constructor), now i want to fire a few commands as a person closes the form or dialog... so is there anything as an unload() method, something that fires just before the form / dialog closes?

Thanks!
LVL 1
lopbandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
Use Closing event of Form (from tab at Properties window).
0
Fernando SotoRetiredCommented:
It is the Closing event it has the following signature :

private void FormName_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
   // ....
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lazyberezovskyCommented:
Sorry, event is called FormClosing. You can find it in "Bahavior" events group.
Or you can subscribe to this event mannually, e.g. inside constructor or Form_Load event handler.
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

lopbandAuthor Commented:
Thanks guys!

A bit puzzled as to who to award this to so am splitting it, because although i got the first correct answer i had no explanation of if, then second answer gave me explanation but based on the first..
0
lazyberezovskyCommented:
Ah man, where have you seen Closing event on Form?
Look:
    public partial class Form1 : Form
    {     
        public Form1()
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }      

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }
    }

Open in new window

0
lopbandAuthor Commented:
What am i doing wrong guys?


namespace RyanSplashScreen
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();
        }

        private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            MessageBox.Show("fired!");
        }

Open in new window

0
lopbandAuthor Commented:
ok, forgot to add this:
this.FormClosing += new FormClosingEventHandler(SettingsForm_FormClosing);

it works!!!

Thanks!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.