Detecting X button click of a window in winforms.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Detecting X button click of a window in winforms.

  1. #1
    Join Date
    Sep 2008
    Posts
    79

    Question Detecting X button click of a window in winforms.

    How can I detect the click event of the close (X) button at the top right corner of the control box of a form/window? Please note, I don't want to know about CloseReason, FormClosing, FormClosed or stuffs like these, unless they are inevitable. I exactly want to detect if the user clicked the X button of the form. Thanks.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: Detecting X button click of a window in winforms.

    I think you need to do 2 things. 1 check the closereason and 2 set a flag anywhere you close the form through code. The closereason will = 3 if the x was clicked or you exited through code so if you set a flag just before you call your close method then in the closing event you check both your flag and the close reason you should be able to tell.

    Flag is false and closereason is 3 x was clicked.
    Always use [code][/code] tags when posting code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center