C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-03-2009, 02:59 AM   #1
Registered User
 
Join Date: Jun 2009
Posts: 21
Editing the Red X Control Button....

Hi,

I've stuck some simple code in my form cancel / ok buttons that disables any predecesing forms, and then enables them and brings them to the front once they are required again.

Is there any way to replicate this code in the Red X control button? I don't want to remove the whole controlbox as I'd like to keep minimise / maximise functionality.

Thanks.
scott_ill is offline   Reply With Quote
Old 09-03-2009, 07:36 AM   #2
Registered User
 
Join Date: Mar 2009
Location: england
Posts: 76
If I understand you correctly, you want the X button to do something and then not close the application? You need to use the OnFormClosing event, which you can place anywhere in your form class:

Code:
protected override void OnFormClosing(FormClosingEventArgs e)
{
    // put your custom code here



    e.Cancel = true; // prevent form closure

    base.OnFormClosing(e);
}
Here's an example, where if you click the X button it shows a dialog asking you to confirm you wish to exit:

Code:
protected override void OnFormClosing(FormClosingEventArgs e)
{
    DialogResult result = MessageBox.Show("Are you sure you want to quit?", "Exit?", MessageBoxButtons.OKCancel);

    if (result != DialogResult.OK)
        e.Cancel = true;
    else
        base.OnFormClosing(e);
}
theoobe is offline   Reply With Quote
Old 09-03-2009, 09:50 AM   #3
Registered User
 
Join Date: Jun 2009
Posts: 21
Great stuff.

Thanks.
scott_ill is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button and edit control border maxorator Windows Programming 4 11-04-2005 02:31 PM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
BN_CLICKED, change button style bennyandthejets Windows Programming 9 09-11-2002 03:59 AM
I need some ideas please>> Unregistered C Programming 3 08-23-2002 01:55 PM
Tab Controls - API -KEN- Windows Programming 7 06-02-2002 09:44 AM


All times are GMT -6. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22