Solved

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

Posted on 2007-11-20
9
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20325140
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
ID: 20325156
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
ID: 20325174
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20325179
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
 

Author Comment

by:EEssam
ID: 20325216
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
ID: 20325247
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
ID: 20325274
OK. What does base.OnFormClosing(e); exactly do?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20325293
0
 

Author Closing Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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