I am trying to figure out how I can trap the Closing Event that occurs when
a user attempts to close the window by clicking on the red"X".
I tried this code which I found online but nothing happens.
What do I need to do to trap and give the ability to save changes before the
window closes?
Thanks,
Ron
private void frmDataEditGrid _Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
if (MessageBox.Sho w("Do you want to save changes to your text?", "My
Application",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
e.Cancel = true;
}
} 4 6448
The code as posted won't work, no (it always stops the close, as e.Cancel is
always set to true), but the Closing event is fine;
The following, added to a form, works for me:
public Form1() { // ctor
// initialise and hook up the closing event (event could also be
attached in the IDE / InitializeCompo nent, but I like it here...)
InitializeCompo nent();
FormClosing += new FormClosingEven tHandler(Form1_ FormClosing);
}
void Form1_FormClosi ng(object sender, FormClosingEven tArgs e) { //
event handler
bool cancel = false; // let the form close by default
if(MessageBox.S how("Cancel?"," Test",MessageBo xButtons.YesNo) ==DialogResult. Yes)
{
cancel = true; // don't close...
}
e.Cancel = cancel;
}
Marc
"RSH" <wa************ *@yahoo.com> wrote in message
news:u4******** ******@TK2MSFTN GP10.phx.gbl... I am trying to figure out how I can trap the Closing Event that occurs when a user attempts to close the window by clicking on the red"X".
I tried this code which I found online but nothing happens.
What do I need to do to trap and give the ability to save changes before the window closes?
Thanks, Ron private void frmDataEditGrid _Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
if (MessageBox.Sho w("Do you want to save changes to your text?", "My Application",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
e.Cancel = true;
}
}
"Marc Gravell" <mg******@rm.co m> a écrit dans le message de news: Oz************* *@TK2MSFTNGP14. phx.gbl...
Simplified to :
void Form1_FormClosi ng(object sender, FormClosingEven tArgs e)
{
e.Cancel = MessageBox.Show ("Cancel?","Tes t",MessageBoxBu ttons.YesNo) ==
DialogResult.Ye s)
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Two quick things... when you say that nothing is happening... I am guessing
you are not even seeing the message box. If that is the case, you need to add
a bit of code to have your function be called when the event is raised.
The easiest way to do that would be to view your form in the form designer,
and in the Properties window click the Events button (has the lightning bolt
icon, and locate the Closing event. Finally, use the drop down to select your
handler, frmDataEditGrid _Closing.
Second, remove the first instance of ‘e.Cancel = true’ which is being called
no matter what. Without it, the option you choose from the prompt will cause
the form to close or not.
Brendan
"RSH" wrote: I am trying to figure out how I can trap the Closing Event that occurs when a user attempts to close the window by clicking on the red"X".
I tried this code which I found online but nothing happens.
What do I need to do to trap and give the ability to save changes before the window closes?
Thanks, Ron private void frmDataEditGrid _Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
if (MessageBox.Sho w("Do you want to save changes to your text?", "My Application",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
e.Cancel = true;
}
}
Thanks alot. I am just starting to understanding wiring events...this was
very helpful. THANKS!
"Marc Gravell" <mg******@rm.co m> wrote in message
news:Oz******** ******@TK2MSFTN GP14.phx.gbl... The code as posted won't work, no (it always stops the close, as e.Cancel is always set to true), but the Closing event is fine;
The following, added to a form, works for me:
public Form1() { // ctor // initialise and hook up the closing event (event could also be attached in the IDE / InitializeCompo nent, but I like it here...) InitializeCompo nent(); FormClosing += new FormClosingEven tHandler(Form1_ FormClosing); }
void Form1_FormClosi ng(object sender, FormClosingEven tArgs e) { // event handler bool cancel = false; // let the form close by default
if(MessageBox.S how("Cancel?"," Test",MessageBo xButtons.YesNo) ==DialogResult. Yes) { cancel = true; // don't close... } e.Cancel = cancel; }
Marc
"RSH" <wa************ *@yahoo.com> wrote in message news:u4******** ******@TK2MSFTN GP10.phx.gbl...I am trying to figure out how I can trap the Closing Event that occurs when a user attempts to close the window by clicking on the red"X".
I tried this code which I found online but nothing happens.
What do I need to do to trap and give the ability to save changes before the window closes?
Thanks, Ron private void frmDataEditGrid _Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
if (MessageBox.Sho w("Do you want to save changes to your text?", "My Application",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
e.Cancel = true;
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Benson |
last post by:
Hi, I'm using Tkinter and would like to know how to replace the red "Tk"
logo in the left corner of the title bar of the root window with some other
icon.
Another question for curiosity's sake:
I've often seen Tkinter referred to as the "standard" Python GUI. I assume
that this is because it may be the oldest and perhaps the most
cross-platform. Is that all that can be said for it? I've already heard
about the Tkinter interpretive...
|
by: elad |
last post by:
Hi
The Menu doesn't work properly when I have 2 frame and the Menu popup
frame=document target frame, when I choose item in
the menu the doc opened and the menu get stuck.
Here is the code I'm using:
FrameSet -------------------------------------------------------
<html>
|
by: Charles Law |
last post by:
For some reason, when I click the X to close my MDI parent form, the action
appears to be re-directed to one of the MDI child forms, and the parent
remains open. I am then unable to close the application.
What should happen, is that the main MDI form should close, taking the child
forms with it. There is code to loop through the child forms, remove the
controls on each of them, and then close the form, but this code should
execute only...
|
by: gsb58 |
last post by:
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
|
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 on btnOk, the program makes some confirm
operations and closes the form.
When the user clicks on btnCancel, the program makes some cancel
operations and closes the form.
My problem is that, when the user clicks on the "X" button of the
form...
| |
by: Mel |
last post by:
I need to draw a red frame around the element under current pointer.
I have seen it done in debuggers, but need to have it in my
application, without the need to download and install applications.
Any help is appreciated
|
by: Brian Kendig |
last post by:
How do I take an index of a literal array, instead of a variable?
That is, say I want to get the short name of a month. Can I do
something like:
$monthname = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec");
or do I always have to do:
|
by: Gestorm |
last post by:
It seems that the standard c library doesn't give any support on
this. I googled this question and found that the code would not be
portable. Then how can I do this under linux ? Thanks! ^_^
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |