Hello every one ...

I have a C# windows based application in which when i press ALT + F4 key at that my window is closed as usual...

but i dont want to close window when user press ALP + F4 key .
User have to close window by clicking close button.

Any one can tell me how can i dont allow user to close application window when user press ALT + F4.

thnks ...

any help please??

Hello.
In your case you can handle those keys in KeyDown event. It would be something like this:

private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            // if AltKey is pressed and the
            //other Key is F4 then
            if (e.Alt && (e.KeyCode == Keys.F4))
            {
                //we say, that we already handled that
                //event by ourself and there's no need to pass
                //this event to other handler, that will
                //recognize the Alt+F4 and close the form
                e.Handled = true;
            }
        }

Why do you care what method/step the user uses to close your application? I see this type of question a lot, and it's generally due to overlooking the behavior of the Form.Closing event..., which is a cleaner approach in my opinion. If the user needs to save data or something, you can notify user and prevent the form from closing.

thanks a lot for your reply ...
finally i got the solution ...
whatever atenka has suggested that i have used to set the flags ..

This question has already been answered. Start a new discussion instead.