473,800 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
2 4961
On May 22, 3:42 pm, LostInMD <LostI...@discu ssions.microsof t.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
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_newsgroup s" wrote:
On May 22, 3:42 pm, LostInMD <LostI...@discu ssions.microsof t.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4178
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind soul please tell me what I'm doing wrong?
6
9217
by: Saso Zagoranski | last post by:
Hi! I have a question regarding Windows Forms... Let's say I have two forms... MainForm and FormTwo... is it possible, when I open FormTwo from MainForm, to display FormTwo inside MainForm instead of in it's own window? Thanks, Saso
0
1251
by: web1110 | last post by:
Hi again, I am referring an earlier question here trying to enlarge upon the concept I am pursuing.: Each object is a subassembly. They are all significantly different in detail and content but are all derived from an abstract subassembly class. An assembly is defined as a tree of subassemblies. There are multiple levels of subassemblies that can be assembled in many different
2
2020
by: marcia | last post by:
How can I capture (i.e., write an event handler) that runs after I press the "Enter" key? I'd like to prevent a Web Form from being submitted when the "Enter" key is pressed following the typing of some characters into a TextBox (ASP.NET) of a Web Form.
7
1735
by: Jon | last post by:
I am having a brain drought here. I used to code in VB until about 3 years ago. I guess it's not quite like a bicycle because man i feel dumb :) Here, quickly, is what i am trying to accomplish... One way or another i need a form to appear inside another form when clicking a command button. Example... I have a Form - we'll call it Form1 - we'll say it has a
1
1203
by: Geoff Jones | last post by:
Hi Can anybody give me some example code on creating a form within another form which is centered to the first form? Thanks in advance Geoff
5
1363
by: mabond | last post by:
Hi all This question is one of "theory" rather than a search for the specifics of a solution. I need some pointers as to how to proceed with my project. Here goes. My application allows the user to select from menu options. Some of the menus allow the user, via an options form, to select parameters for the display of reports. Those parameters will include things like the date range,
7
6789
by: Miro | last post by:
I can use the property of the Form to remove the "x" from the top of the form. Is there a way in VB to leave the X there but program something so you cannot close the form? Or like an ONCLOSE event that you can just put "cancel" ? If i remember correctly...back in vb 1.0 days or so there was a canclose on the form.
1
3473
by: HarpoleAndWhite | last post by:
I am trying to put together a point of sale system for a restaurant. On the servers menu, I would like to have command buttons that on their click event load a secondary form onto the servers menu (in a subform or display box, etc.). For example, once the lunch button is clicked, the lunch form should load into the servers menu (via a subform, etc.) containing more command buttons that are linked to database food items. What kind of...
2
1383
by: menyki | last post by:
please can somebody help me debug this code. i wrote a code that will display a form within an interval but the is generating alot of errors. the code is as shown below. (am using visual basic.Net) Dim myTimer As New System.Timers.Timer myTimer.Enabled = True myTimer.Interval = 70 Me.Close() mainForm.Show()
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.