Hi!
In my application I have code that will give the user a choice when he
click's the close button on the ToolBar1.
However, when he clicks the close button of the form, the form will
shut down even if he chooses the cancel button of the messagebox that
pop's up.
Now...if he, on the other hand, chooses ALT+F4, then I catch this in
code and then the cancel button works very well. The code goes like:
Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Try
If (e.Alt) = Keys.F4 Then
MyShuttingDownAction()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
End Try
End Sub
So I've tried to catch the form's close button in the form's OnClosing
event, but it doesn't respond to the code I've written, which goes like
this:
Public Sub MyShuttingDownAction()
Dim intRes As Integer
Try
intRes = MessageBox.Show("U LEAVE ME?", _
"BYE?", _
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If intRes = DialogResult.Cancel Then
StatusBar1.Panels(4).Text = "STILL HERE?"
ElseIf intRes = DialogResult.OK Then
Application.Exit()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK,
MessageBoxIcon.Warning)
End Try
End Sub
Hope anybody could point me in the right direction.
Me.Name 5 2106
Hi,
Dim a boolean that has scope for the form class.
when you meet conditions acceptable for the form to close, set the variable
true.
In the Forms Closing Event, cancel the close if the variable (flag) is not
set.
eg
Private Sub FormLocalSettings_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
e.Cancel = Not fClose
End Sub
<gs***@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... Hi!
In my application I have code that will give the user a choice when he click's the close button on the ToolBar1.
However, when he clicks the close button of the form, the form will shut down even if he chooses the cancel button of the messagebox that pop's up.
Now...if he, on the other hand, chooses ALT+F4, then I catch this in code and then the cancel button works very well. The code goes like:
Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Try If (e.Alt) = Keys.F4 Then MyShuttingDownAction() End If Catch ex As Exception MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End Sub
So I've tried to catch the form's close button in the form's OnClosing event, but it doesn't respond to the code I've written, which goes like this:
Public Sub MyShuttingDownAction() Dim intRes As Integer
Try intRes = MessageBox.Show("U LEAVE ME?", _ "BYE?", _ MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If intRes = DialogResult.Cancel Then StatusBar1.Panels(4).Text = "STILL HERE?" ElseIf intRes = DialogResult.OK Then Application.Exit() End If Catch ex As Exception MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End Sub
Hope anybody could point me in the right direction.
Me.Name
Thanks Doug!
It really stopped the form from closing.
However, if I'd like to call MyShuttingDownAction(), how would I go
about?
Or am I way out on the hillside?
Me.Name
Sorry this was a response to the message below in the list
"Doug Bell" <Po*********@vodaphone.com.au> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl... Hi,
Dim a boolean that has scope for the form class.
when you meet conditions acceptable for the form to close, set the
variable true.
In the Forms Closing Event, cancel the close if the variable (flag) is not set.
eg
Private Sub FormLocalSettings_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
e.Cancel = Not fClose
End Sub <gs***@hotmail.com> wrote in message news:11**********************@g49g2000cwa.googlegr oups.com... Hi!
In my application I have code that will give the user a choice when he click's the close button on the ToolBar1.
However, when he clicks the close button of the form, the form will shut down even if he chooses the cancel button of the messagebox that pop's up.
Now...if he, on the other hand, chooses ALT+F4, then I catch this in code and then the cancel button works very well. The code goes like:
Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Try If (e.Alt) = Keys.F4 Then MyShuttingDownAction() End If Catch ex As Exception MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End Sub
So I've tried to catch the form's close button in the form's OnClosing event, but it doesn't respond to the code I've written, which goes like this:
Public Sub MyShuttingDownAction() Dim intRes As Integer
Try intRes = MessageBox.Show("U LEAVE ME?", _ "BYE?", _ MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If intRes = DialogResult.Cancel Then StatusBar1.Panels(4).Text = "STILL HERE?" ElseIf intRes = DialogResult.OK Then Application.Exit() End If Catch ex As Exception MessageBox.Show(ex.Message, "HEY!", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End Sub
Hope anybody could point me in the right direction.
Me.Name
Hi!
I solved it
I just added the private sub MyShuttingDownAction:
Dim intRes As Integer
Try
intRes = MessageBox.Show("U LEAVE ME?", _
"BYE?", _
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If intRes = DialogResult.Cancel Then
StatusBar1.Panels(4).Text = "CANCELLED"
e.Cancel = True
ElseIf intRes = DialogResult.OK Then
e.Cancel = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "HALLÅ!",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
Thanks anyway!
Me.Name This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wugi |
last post by:
I'm trying to find an equivalent of key-event trapping which is easy in
QBasic. Several of my programs build up a geometric figure with two
parameter line families, eg with two nested for..next...
|
by: Jules Winfield |
last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
|
by: Paul |
last post by:
I have an Access 2000 database with a form that is giving me some
major headaches. When you open the form, it displays all records and
allows editing, but has AllowAdditions set to False so that...
|
by: RAJ |
last post by:
hi
plz tell me how to know "how window is going to close"...
i have to right code for X button of forms...
plz telll me
thanks
bye
|
by: Marty |
last post by:
Hi,
How can I detect that a VS.NET2003 C# form is closed with the upper
right "X" button ?
This is because I want to add code to the myForm.OnClosing() event to do
a different process if a...
|
by: Steve McLellan |
last post by:
Hi all,
I'm trying to override Form events (for example OnClosing or OnClose) with
the intention of preventing the base class function from happening. My
functions are getting called but so are...
|
by: Phill W. |
last post by:
Has any come across a situation where, in a Form-derived .. er .. Form,
the Event Arguments passed to OnClosing /already/ have their Cancel
argument set to True?
Protected Overrides Sub...
|
by: polocar |
last post by:
Hi,
I'm writing a C# program that interfaces with a SQL Server 2005
database (I use Visual Studio 2005 Professional Edition as compiler).
I have defined the classical ADO.NET SqlDataAdapter,...
|
by: polocar |
last post by:
Hi,
suppose that you have a C# form with two buttons, that are the
classical "btnOk" and "btnCancel" (besides them, of course in
the form there can be many other controls).
When the user clicks...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
| |