Forum guidelines
AuthorQuestion
How to program Close button of Windows Form
Posted on: 09 Jan 2004
Hello! I would like to know how to program the Windows Form "Close" button to do other thing, e.g. Disable it, Minimize Windows etc.
AuthorReply
Re: How to program Close button of Windows Form
Posted on: 09 Jan 2004  
Just tap the Form CLosing event: private void fBMIExample_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; }
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Hello! jpf, It's doesn't work. Why? Please give me reply asap. Thanks!
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
From the event list select "closing" that will generate an event in code .Try the following codes. This is working. Should work at your end as well private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel=true; this.WindowState=System.Windows.Forms.FormWindowState.Minimized; } This is a funny piece of thing ;) Enjoy
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Hello! Shayer009, I have tried your code, but when I click on the "X" from the Windows Form, it will close the program not minimize it. Please tell me why? Thanks!
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
It will Close the program ???? have u test that. I test the code and its working fine at my end without any problem. try Closing event. I am not sure what happening at ur end. Can u pls provide the piece of code u are trying .
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Hello! Shayer009, Would you mind to send your coding for me. Please email it to softairhk@hotmail.com. Thanks!
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Not a problem. I have sent that 2 u .
Re: How to program Close button of Windows Form -- ur address bouncing
Posted on: 11 Jan 2004  
Your address is bouncing Pls Check softairhk@hotmail.com is it ur address
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Hello! Shayer009, Can you send your coding to me again, as I still haven't received it? Thanks!
Re: How to program Close button of Windows Form
Posted on: 11 Jan 2004  
Hello! Shayer009, Please send it to softfairhk@yahoo.com. Thanks!
Re: How to program Close button of Windows Form
Posted on: 12 Jan 2004  
The code works. Are you just adding the code to your form and not putting in the event? You need something like this in your form's Initialize Region: this.Closing += new System.ComponentModel.CancelEventHandler(this.fBMIExample_Closing); You can add it yourself, or when you're in the form's designer view, you can click on the lightning bolt for the form properties, then double click on the Closing event, and it will add it for you.
Re: How to program Close button of Windows Form
Posted on: 20 Jun 2012  
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.WindowsShutDown) return;
            // Confirm user wants to close
            switch (MessageBox.Show(this, "Are you sure you want to close?", "Closing", MessageBoxButtons.YesNo,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button2))
            {
                case DialogResult.No:
                    e.Cancel = true;
                    break;
                default:
                    break;
            }
        }

Employers - Post Free Jobs

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.