How to capture user clicking form's "X" (within the controlbox)

G

Guest

Hi All,

I am trying to determine if the user clicked the "x" close button within the
controlbox of the form (top right corner - next to minimize and maximize
buttons).

I am using the datagridview within VB2005. I validate the values in the row
when the user leaves the row via the grid's RowValidating event. I want to
allow the user to exit the application by clicking the "x".

The problem: The RowValidating event is triggered before the form's closing
event. If the user has entered invalid data, I do not allow the user to
leave the row until the the data has been corrected. However, if the user
clicks the "x", I don't want the user to have to fix the bad value before
exiting the application, I just want the application to close. I need a way
to determine if the user clicked the "x" - from within the RowValidating
event. I've taken the long route and figured out the cursor's position and
the approximate size of the the "x" box and it's position - in order to
figure out if the cursor is within the "x" area, however I'm thinking there's
got to be a more efficient way of determining whether the user clicked the
"x". I have other buttons on the form that I check the .Focused property of
(ex. if I'm in the midst of the RowValidating event, I can determine if the
user clicked the Add button by checking whether cmdAdd.Focused = True) to
determine whether the user clicked them.

Thanks in advance for any assistance that is offered! Have a great day!
 
R

rowe_newsgroups

Hi All,

I am trying to determine if the user clicked the "x" close button within the
controlbox of the form (top right corner - next to minimize and maximize
buttons).

I am using the datagridview within VB2005. I validate the values in the row
when the user leaves the row via the grid's RowValidating event. I want to
allow the user to exit the application by clicking the "x".

The problem: The RowValidating event is triggered before the form's closing
event. If the user has entered invalid data, I do not allow the user to
leave the row until the the data has been corrected. However, if the user
clicks the "x", I don't want the user to have to fix the bad value before
exiting the application, I just want the application to close. I need a way
to determine if the user clicked the "x" - from within the RowValidating
event. I've taken the long route and figured out the cursor's position and
the approximate size of the the "x" box and it's position - in order to
figure out if the cursor is within the "x" area, however I'm thinking there's
got to be a more efficient way of determining whether the user clicked the
"x". I have other buttons on the form that I check the .Focused property of
(ex. if I'm in the midst of the RowValidating event, I can determine if the
user clicked the Add button by checking whether cmdAdd.Focused = True) to
determine whether the user clicked them.

Thanks in advance for any assistance that is offered! Have a great day!

I am trying to determine if the user clicked the "x" close button within the
controlbox of the form (top right corner - next to minimize and maximize
buttons).

http://groups.google.com/group/micr...st&q=herfried+wndproc&rnum=1#c4b18f899f58b66a

Thanks,

Seth Rowe
 
G

Guest

Hi Seth,

Thanks for your help. For whatever reason, the code from the link does not
work as it should. I was using that method at one point within my code, but
as I began using more of the datagridview's events, that logic stopped
working. I would be interested to know if you have any other suggestions.
Thanks again for your assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top