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?
 
Fernando SotoRetiredCommented:
It is the Closing event it has the following signature :

private void FormName_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
   // ....
}
0
 
lazyberezovskyCommented:
Use Closing event of Form (from tab at Properties window).
0
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.