I need to make sure that the user cannot close (using "X") the form before
saving the data on it. Which form event should I write the control code in?
Thank you,
-Delen 11 2882
Look at the forms Closing event.
Define a form level var that you can set to tru if your forms data is dirty
and trigger of that in the event...
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
If (isDirty = True) Then
e.Cancel = True
End If
End Sub
"Dursun" <Du****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com... I need to make sure that the user cannot close (using "X") the form before saving the data on it. Which form event should I write the control code
in? Thank you,
-Delen
Durson,
There are in my opinion only two kind of options which do prevent you that a
user blames you that your program has a bug when he pushes the X and
nothing happens.
That is catching it in the closing event and than ask with a messagebox to
close or not and than set the e.cancel.
Or this nice solution from Mike, because then there is no X what in my
opinion is much nicer. http://www.gotdotnet.com/Community/M...&Page=1#248801
I hope this helps,
Cor
"Dursun" <Du****@discussions.microsoft.com> schrieb: I need to make sure that the user cannot close (using "X") the form before saving the data on it. Which form event should I write the control code in?
\\\
Imports System.ComponentModel
..
..
..
Private Sub Form1_Closing( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles MyBase.Closing
If _
MsgBox( _
"Really close?", _
MsgBoxStyle.YesNo Or MsgBoxStyle.Question _
) = MsgBoxResult.No _
Then
e.Cancel = True
End If
End Sub
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
I also like the no "X" option. However, I have a problem with forms that I
set the ControlBox to False so it doesn't show. I also set the StartPosition
to Manual then set the form location in code depending on the situation. The
form has the bottom 1/4 chopped off and doesn't show. If I change the
ControlBox to True, the form shows fine in the proper location to which I set
it. Any idea what causes this?
"Cor Ligthert" wrote: Durson,
There are in my opinion only two kind of options which do prevent you that a user blames you that your program has a bug when he pushes the X and nothing happens.
That is catching it in the closing event and than ask with a messagebox to close or not and than set the e.cancel.
Or this nice solution from Mike, because then there is no X what in my opinion is much nicer.
http://www.gotdotnet.com/Community/M...&Page=1#248801
I hope this helps,
Cor
Dennis,
With this code while the first is false or true the form comes forever on
the same place.
\\\
Me.ControlBox = False
Me.StartPosition = FormStartPosition.Manual
Me.Height = 400
Me.Width = 400
Me.Left = 400
Me.Top = 400
////
So can you explain something more?
Cor
"Cor Ligthert" <no************@planet.nl> schrieb: There are in my opinion only two kind of options which do prevent you that a user blames you that your program has a bug when he pushes the X and nothing happens.
That is catching it in the closing event and than ask with a messagebox to close or not and than set the e.cancel.
Or this nice solution from Mike, because then there is no X what in my opinion is much nicer.
Mhm... From a usability standpoint that's a bad choice because the user
should have a way to exit the application. I'd choose the way chosen by
many other applications, that is showing a messagebox that asks the user to
save the data and dispose the data if the user replies with "No". If there
is no data to save no messagebox needs to be shown and the application can
terminate.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried, That is catching it in the closing event and than ask with a messagebox to close or not and than set the e.cancel.
Mhm... From a usability standpoint that's a bad choice because the user should have a way to exit the application. I'd choose the way chosen by many other applications, that is showing a messagebox that asks the user to save the data and dispose the data if the user replies with "No". If there is no data to save no messagebox needs to be shown and the application can terminate.
What do I see wrong?
The code you showed had not any comment from me, because that is what I
advice.
:-)
Cor
You are correct...this works. However, delete the line Me.ControlBox = False
and go the the IDE and set the Controlbox to False in the property box. Then
run it. You will find that the bottom 1/4 of the form does not show up.
Bottom line is if you set the controlbox to false in code, it works ok but if
you set it in the IDE property list at design time, it doesn't.
"Cor Ligthert" wrote: Dennis,
With this code while the first is false or true the form comes forever on the same place.
\\\ Me.ControlBox = False Me.StartPosition = FormStartPosition.Manual Me.Height = 400 Me.Width = 400 Me.Left = 400 Me.Top = 400 //// So can you explain something more? Cor
Dennis,
I did as you said.
Then I added a statusbar
The form shows up donw in my screan (as it should with a part hidden).
When I than drag it up, I see a full form that I can by the statusbar handle
(right on screen not the windowshandle) make smaller and larger.
Where don't we understand each other?
Cor
Dennis,
No I did not scream when I saw it down on my screen.
:-)
Cor
I tried creating a new project and can't seem to reproduce the error in the
new simple project. However, if I set the Startposition to Manual in code in
my large project, all seems to work well. I guess I'll just go with that.
Thanks Cor for the help.
"Cor Ligthert" wrote: Dennis,
I did as you said. Then I added a statusbar The form shows up donw in my screan (as it should with a part hidden). When I than drag it up, I see a full form that I can by the statusbar handle (right on screen not the windowshandle) make smaller and larger.
Where don't we understand each other?
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Horowitz |
last post by:
Hi folks,
I want to be able to store and retrieve UNSAVED Word documents as BLOBs. I
got all the info for storing them if they're already saved on the file
system. But what if they're not...
|
by: Jeff User |
last post by:
Hi all
I am using an OleDbDataReader.
I need to establish and then keep the connection that I use, but I do
not need to keep the data reader, after this operation is over.
Therefore, regardless...
|
by: markalroberts |
last post by:
Hi,
I wish to ask warn the user that there are unsaved changes (if there
are) and allow them to cancel navigating away/closing the browser.
Investigation leads me to believe the...
|
by: chris |
last post by:
Hi,
I write some code guarded with exception handling...
simplified code look like this...
int main(int argc, char* argv){
try{
|
by: tshad |
last post by:
Normally, I surround my Dataset/fill or DBreader execut with a try/Catch.
Something like:
******************************************************
Dim dbReader As SqlDataReader
Dim...
|
by: Strah |
last post by:
Is there a way to catch the event of terminating the application from the the
processes tab in task manager?
I have created windows app, and if a user termintates the app in the task
manager,...
|
by: neoret |
last post by:
Hello.
I need a helping hand to help me send an unsaved dokument through a
POST call.
I have added functionality to word and want to send a unsaved document
through a POST call. This works...
|
by: ChalkStream |
last post by:
Well, it was saved onto my USB. Then I opened it, edited it, left it. When I came back someone had switched user and when I logged back in every thing crashed and I lost all the work. I restarted it...
|
by: khushbu shah |
last post by:
In my website we have left panel having different links, our requirement when user clicks on any link and enter any detail on page without save/submit, and then he moves to next link on left...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |