473,698 Members | 2,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

e.Cancel

Hi you al
I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goe

' Calls this method from the InitializeCompo nent() method of your form
Private Sub OtherInitialize (
AddHandler Me.Closing, AddressOf Me.Form1_Cance
End Sub 'OtherInitializ

Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs
If Not myDataIsSaved The
e.Cancel = Tru
MessageBox.Show ("You must save first."
Els
e.Cancel = Fals
MessageBox.Show ("Goodbye."
End I
End Sub 'Form1_Cance

Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the "Protected Sub Form1_Cancel
Thank

Nov 20 '05 #1
6 8572
Hi Carl,
I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goes

You do not need that, just open in your form code the uper left combobox and
choose form1_events. Than in the right combobox "Closing"

The sub with the handler in it will be completly made. There you can paste
in the syntax you have now in the sub Form_Cancel (Than others will probably
as well understand better your code, en needed by instance when you send a
snippet to this newsgroup).

You can as well delete that first sub and set the addhandler sentence in
the load event from your page, however it is than a little bit not done
code.

I hope this helps?

Cor

' Calls this method from the InitializeCompo nent() method of your form.
Private Sub OtherInitialize ()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
End Sub 'OtherInitializ e

Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
If Not myDataIsSaved Then
e.Cancel = True
MessageBox.Show ("You must save first.")
Else
e.Cancel = False
MessageBox.Show ("Goodbye.")
End If
End Sub 'Form1_Cancel

Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the
"Protected Sub Form1_Cancel" Thanks

Nov 20 '05 #2
"Carl" <an*******@disc ussions.microso ft.com> schrieb
Hi you all
I am new to this stuff and I found this code to close a form in the
help files and I do not understand it or where its goes

' Calls this method from the InitializeCompo nent() method of your
form. Private Sub OtherInitialize ()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
End Sub 'OtherInitializ e

Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
If Not myDataIsSaved Then
e.Cancel = True
MessageBox.Show ("You must save first.")
Else
e.Cancel = False
MessageBox.Show ("Goodbye.")
End If
End Sub 'Form1_Cancel

Forget about the myDataIsSaved stuff. I am trying to know where in
the form to put the "Sub OtherInitialize ". where ito call it from and
to put the "Protected Sub Form1_Cancel" Thanks


What's your intention? To close a Form, call it's Close method. The closing
event occurs before the Form get's closed. In the event handler you can set
e.cancel = true to stop the Form from being closed. If it is closed, the
Closed event occurs.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Hi Armin,

I saw this message at 10:37 (our time) is there something strange or is this
normal?

While I had seen the message from Pieter (DraguVaso) before that in an
earlier refresh.

Cor
Nov 20 '05 #4
* "=?Utf-8?B?Q2FybA==?=" <an*******@disc ussions.microso ft.com> scripsit:
I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goes

' Calls this method from the InitializeCompo nent() method of your form.
Private Sub OtherInitialize ()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
This adds a handler to the form's 'Closing' event. This event is fired
when the user or the system is trying to close the form.
End Sub 'OtherInitializ e

Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
If Not myDataIsSaved Then
'myDataSaved' is a private variable of type 'Boolean' that is set if
data has been saved. If it's not yet saved, a messagebox is shown that
tells the user to save data. In the saving procedure, the Boolean
variable is set.
e.Cancel = True
MessageBox.Show ("You must save first.")
Else
Data been saved, so exit-
e.Cancel = False
MessageBox.Show ("Goodbye.")
End If
End Sub 'Form1_Cancel

Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the "Protected Sub Form1_Cancel"
Thanks


You put it after the call to 'InitializeComp onent' in your 'Sub New'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Hi Herfried,

I did advice 3 hours ago not to use this method, can you descibe why it
should be done in this way and not in the way as it is build in by
Microsoft?

Cor
* "=?Utf-8?B?Q2FybA==?=" <an*******@disc ussions.microso ft.com> scripsit:
I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goes
' Calls this method from the InitializeCompo nent() method of your form.
Private Sub OtherInitialize ()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel


This adds a handler to the form's 'Closing' event. This event is fired
when the user or the system is trying to close the form.
End Sub 'OtherInitializ e

Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
If Not myDataIsSaved Then


'myDataSaved' is a private variable of type 'Boolean' that is set if
data has been saved. If it's not yet saved, a messagebox is shown that
tells the user to save data. In the saving procedure, the Boolean
variable is set.
e.Cancel = True
MessageBox.Show ("You must save first.")
Else


Data been saved, so exit-
e.Cancel = False
MessageBox.Show ("Goodbye.")
End If
End Sub 'Form1_Cancel

Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the
"Protected Sub Form1_Cancel" Thanks


You put it after the call to 'InitializeComp onent' in your 'Sub New'.

Nov 20 '05 #6
* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
I did advice 3 hours ago not to use this method, can you descibe why it
should be done in this way and not in the way as it is build in by
Microsoft?


Using 'Handles' is not much different from using 'AddHandler'. I would
do that the way you described too, but I thought it's still important to
tell the OP what the code is doing.

Just my 2 Euro cents...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8340
by: AP | last post by:
Hi, I'm trying to use c# to pop up a dialog box when a user attempts to close word to prompt them if they want to exit or cancel (obviously other stuff needs to happen based on their selection but that's the gist of it.) I have everything set up, and it seems to work except that setting Cancel to true and returning from my c# method appears to do nothing. Word still closes. Am I doing something wrong? private void...
13
2318
by: Mike L | last post by:
I have a child form frmDataEntry call up another child form frmDealerSearch. If the user clicks on cancel on frmDealerSearch, I want to close frmDealerSearch and put the focus on txtDealerNum on frmDataEntry. Here is my code. public class frmDataEntry : System.Windows.Forms.Form { private void txtDealerNum_Leave(object sender, System.EventArgs e) {
14
2624
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a template which is not such a bad thing in itself but it means all other controls in the application must also be converted to templates to maintain a consistent UI. So much for writing 70% less code when foolish morons release a control with no cancel...
3
2771
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set the value to False, but I would have expected it to be False on entry. TIA Charles
21
9166
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
2
4802
by: Robinson | last post by:
I can start an Asynchronous operation against a data source with SQLCommand.BeginExecuteReader, allowing me to loop, checking for user cancellation before the operation has completed, but how then to cancel the SQLCommand if the user wishes to? The "Cancel" method states: ".......... The Cancel method cannot be used to cancel a pending asynchronous operation." The scenario I'm thinking about here concerns a potentially long-running...
4
3001
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by another when its form Closing routine is run? I guess what I'm asking is will that work. If one form sets e.cancelled to true will e.cancel be true when the next form receives a closing event?
2
635
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel? ----------------------------------------------------------------------- The buttons on a confirm box cannot be changed, nor can you specify a default button. However, you should be able to change the question so that "OK" is suitable as the default. e.g. change "We will now buy ourselves...
16
2426
by: parez | last post by:
I start a BackGroundWorker to populate a grid. It is started off in the ui layer The thread follows( cannot think of a better word) the path UI->Layer1->Layer2->Communication Layer and it blocks (the server is executing somthing where which takes time)
5
13594
by: ghjk | last post by:
I have "cancel" button in php files. I want to write common javascript function for cancel button. When user click cancel button I want to clear php form data. Is it possible? <input id="Cancel" src="Cancel.jpg" type="image" alt="cancel" onclick="Cancel('cancel');"/> JS code function Cancel(cancel){ if(cancel=='cancel'){
0
8603
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,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
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
8861
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...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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
4366
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.