Solved

How can I call this.Hide(); when the app is closed by clicking the X

Posted on 2007-11-20
9
236 Views
Last Modified: 2013-12-17
Hi,

I want to only hide the form when the title bar red X is clicked.

How may I do so?

Thanks.
0
Comment
Question by:EEssam
  • 5
  • 4
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
inside your form:

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)  
            {
                       e.Cancel = true;
                       this.Hide();
             }
              else
                  base.OnFormClosing(e);
        }
0
 

Author Comment

by:EEssam
Comment Utility
Worked but I got:

An unhandled exception of type 'System.StackOverflowException' occurred in app.exe

When Application.Exit() was run.
0
 

Author Comment

by:EEssam
Comment Utility
Please note:

1. When I comment the two lines:

else
                base.OnFormClosing(e);

The error goes...

2. The form I applied your code to is not the main form and I'm closing the application from the main form.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
Hmm, not sure at this moment. Try to remove the 'else'


protected override void OnFormClosing(FormClosingEventArgs e)

{

     if (e.CloseReason == CloseReason.UserClosing)  

     {

         e.Cancel = true;

         this.Hide();

     }

     base.OnFormClosing(e);

}

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:EEssam
Comment Utility
The same error. Everything is cool when I remove:

else
                  base.OnFormClosing(e);

Why should I keep it?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
Because it is recommended by the MSDN documentation. Indeed I have an application with this approach, don't know why it is not working for you. Maybe it is interfering with other event.
0
 

Author Comment

by:EEssam
Comment Utility
OK. What does base.OnFormClosing(e); exactly do?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
0
 

Author Closing Comment

by:EEssam
Comment Utility
Since I just want to hide the form, I just removed: else
                  base.OnFormClosing(e);
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
LINQ question 7 20
Pass through dll 2 33
Get String split 5 31
Get list of word ducuments in a folder 10 9
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now