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

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.

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

:icon_sad:

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.

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

public Form1()
        {
            InitializeComponent();
            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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.