473,387 Members | 1,771 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,387 software developers and data experts.

Stopping the Cancel button

I have a dialog box with a Cancel button that I want to be activable with
the ESC key. In the form the Cancel button is connected to the CancelButton
property. Now my problem is that the OnClick event of the button must be
able to "stop" the closing of the form: I want to change the text of the
Cancel button (that stops some working done in the background) to "Close"
and only the second time it's pressed it will close the dialog.... But I'm
not able to do it. How should I do?

Thanks!
May 23 '07 #1
4 3088
Hi,

Are you sure you want to do this?
The user expect certain functionality which is shared by all the window
apps. if you change this the user can feel disoriented.

Use the onClick of the button, and use a flag if the flag is set the onclick
will close it, somethig like:

bool clickedonce = false;
void button_click( ..)
{
if (!clickedOnce)
{ cancelButton.Text = "Close";
clickedonce = true;
//do the other stuff
}
else
this.Close()

}

"MaxMax" <no**@none.comwrote in message
news:i1******************@twister2.libero.it...
>I have a dialog box with a Cancel button that I want to be activable with
the ESC key. In the form the Cancel button is connected to the CancelButton
property. Now my problem is that the OnClick event of the button must be
able to "stop" the closing of the form: I want to change the text of the
Cancel button (that stops some working done in the background) to "Close"
and only the second time it's pressed it will close the dialog.... But I'm
not able to do it. How should I do?

Thanks!

May 23 '07 #2
On Wed, 23 May 2007 02:43:42 -0700, MaxMax <no**@none.comwrote:
I have a dialog box with a Cancel button that I want to be activable with
the ESC key. In the form the Cancel button is connected to the
CancelButton
property. Now my problem is that the OnClick event of the button must be
able to "stop" the closing of the form: I want to change the text of the
Cancel button (that stops some working done in the background) to "Close"
and only the second time it's pressed it will close the dialog....
I'll second the motion that it's not a good idea to have a dual-purpose
button.

If the semantics of your dialog box really include: aborting background
processing, canceling the results, and accepting the results, then you
should have three buttons. The "Okay" and "Cancel" buttons should be
disabled while background processing is happening, if you don't want the
dialog to be dismissed while the processing is going on. This provides
the user with clear feedback that the dialog cannot be dismissed while the
processing is still happening (don't forget to disable the "X" close
button for the window :) ). Likewise, once the background processing has
stopped (because the user stopped it or it completed) then the "abort
processing" button should be disabled and the "Okay" and "Cancel" buttons
can be enabled.

Then you can include a ProcessDialogKey() method that will watch for the
escape key if the processing is still going on, and map that key to
aborting the processing rather than dismissing the dialog if and when it
is pressed.

Pete
May 23 '07 #3
Hi Max,

Based on my understranding, you have a button on a form and set the
CancelButton property of the form to this button. When you show the form
modally and press the Esc key, the button is activated and the form is
closed. What you want is to change the text of the button to "Close" for
the first time you press the Esc key or click the button, and close the
form for the second time you do the same thing. If I'm off base, please
feel free to let me know.

If you are using VS05, a solution is to handle the FormClosing event of the
form. We could make use of the CloseReason property of the
FormClosingEventArgs parameter to judge what causes the form to be closed.
When we press the Esc key to click the button on the form, the CloseReason
property is None.

The following is a sample.

public partial class Form1 : Form
{
public Form4()
{
this.FormClosing += new
FormClosingEventHandler(Form1_FormClosing);
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.None)
{
if (this.cancelBtn.Text != "Close")
{
this.cancelBtn.Text = "Close";
e.Cancel = true;
}
}
}
}

Hope this helps.
If my suggestion is not appropriate to your practice, please feel free to
let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

May 24 '07 #4
If you are using VS05, a solution is to handle the FormClosing event of
the
form. We could make use of the CloseReason property of the
FormClosingEventArgs parameter to judge what causes the form to be closed.
When we press the Esc key to click the button on the form, the CloseReason
property is None.
Thanks! It works!!!

--- bye
May 24 '07 #5

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

Similar topics

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...
5
by: Oenone | last post by:
I have a VB.NET form which I'm displaying modally using the ShowDialog() method. Within the form is a Cancel button, and I've set this button into the Form's CancelButton property so that...
2
by: alexander.glass | last post by:
I have a buffered page that runs some code and outputs to the user to update the progress of a method that takes several minutes to run. I have a big problem however. There is no way to stop the...
3
by: Jon Delano | last post by:
Hi I was wondering if it were possible to somehow stop a page from posting back to the server and running the server side code. I have a datagrid and the first column is basically a button. I...
0
by: Jason | last post by:
I'm reading that this is by design.. but It's just killing me. I see all sorts of nice events - onclick, onupdating, onupdating .. I can cancel the update with e.cancel etc... Great. So why...
4
by: PW | last post by:
Hi, I want to add code to check if the user wants to save the record (fields are unbound) when they press the form's close (X) button. Is it possible to return the user to the form if there...
2
by: Mark | last post by:
I have a form with two sub forms. The form is set to data entry. The form is bound directly to a table I have two buttons at the bottom of the screen. One button is named reject and one is named...
4
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
3
by: Yash | last post by:
Hi, In our ASP .NET application we present a form wherein the user has to input a number of fields. If in the middle of filling the form, the user accidentally navigates away from the page,...
0
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,...
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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 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.