how can i control the close button in a form....
(the three bottons minimize,maxi,close for all windows form)
i hav attached a fig... jst check it...
n pls reply

Attachments untitled.JPG 20.36 KB
8 Years
Discussion Span
Last Post by Diamonddrake

You can handle the close event on the form using the following event handler:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            if (DialogResult.No == MessageBox.Show("Exit without saving changes?", "Data Not Saved", MessageBoxButtons.YesNo))
                e.Cancel = true;

The above event will be called whenever the Close() method is executed. Use e.Cancel = true to stop the form from being closed.

Edited by DdoubleD: n/a


Hey its not working...
sud i doudl click smthing jst lik in case of bottons
doubleclicking on that "red cross" results in page load...



Double clicking on a control will create the default event handler. To create handles for other events, got to the properties panel and change to the Events section (lightning bolt at top).
Then double click on the area next to the required event and a basic event handler will be created for you.

Check out the image to see where you ened to click.

Remember to mark the thread as solved if this answered your question.

Attachments eventhandle.png 13.98 KB

You can also add the event handler directly in your form's constructor in the form of:

public Form1()
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);

If you need to customize all 3 of the buttons events, the standard practice is to create a your own title bar control such as seen on AIM and Y! instant messengers.

otherwise, DDoubleD has the right idea.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.