By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
May 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 22, 3:42 pm, LostInMD <LostI...@discussions.microsoft.com>
wrote:
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/micro...b18f899f58b66a

Thanks,

Seth Rowe
May 23 '07 #2

P: n/a
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!

"rowe_newsgroups" wrote:
On May 22, 3:42 pm, LostInMD <LostI...@discussions.microsoft.com>
wrote:
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/micro...b18f899f58b66a

Thanks,

Seth Rowe
May 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.