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.