473,244 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,244 software developers and data experts.

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 InitializeComponent() method of your form
Private Sub OtherInitialize(
AddHandler Me.Closing, AddressOf Me.Form1_Cance
End Sub 'OtherInitializ

Protected Sub Form1_Cancel(sender 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 8515
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 InitializeComponent() method of your form.
Private Sub OtherInitialize()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
End Sub 'OtherInitialize

Protected Sub Form1_Cancel(sender 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*******@discussions.microsoft.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 InitializeComponent() method of your
form. Private Sub OtherInitialize()
AddHandler Me.Closing, AddressOf Me.Form1_Cancel
End Sub 'OtherInitialize

Protected Sub Form1_Cancel(sender 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*******@discussions.microsoft.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 InitializeComponent() 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 'OtherInitialize

Protected Sub Form1_Cancel(sender 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 'InitializeComponent' 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*******@discussions.microsoft.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 InitializeComponent() 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 'OtherInitialize

Protected Sub Form1_Cancel(sender 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 'InitializeComponent' in your 'Sub New'.

Nov 20 '05 #6
* "Cor Ligthert" <no**********@planet.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
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...
13
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...
14
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...
3
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...
21
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...
2
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...
4
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...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
16
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...
5
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"...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.