Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have two forms form1 and form2
in form1 i have given a button click event. which shows the second form.
by
XML
form2 f2 = new form2();
this.hide;
f2.show();


and in second form i have used a form closing event like this

C#
public void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {

            if (MessageBox.Show("do you want to save changes to your text?", "My application", MessageBoxButtons.YesNo) == DialogResult.No)
            {

                e.Cancel = true;

            }

            else
            {

                e.Cancel = false;
            }

but i manually have to stop debugging.
how to stop debugging by clickign the default form close button{X button}
Posted
Comments
[no name] 16-Sep-12 12:49pm    
Probably because whatever "this" is, is probably the main form and the application won't exit until that form is closed.
shaikh-adil 16-Sep-12 12:51pm    
how can i do that. give me some more hint bro. i am learning .net
Sergey Alexandrovich Kryukov 16-Sep-12 13:41pm    
Does it work properly without debugging? I'm asking because debugging is not a problem; you can always stop debugging via IDE.
--SA
shaikh-adil 16-Sep-12 15:16pm    
yup the code is right. But i have to stop debugging myself. I thot there would be some problem when i make .exe file of such application. So i thought stoping debugging automatically will be good as compare to manual.

you may use :
Application.Exit();
 
Share this answer
 
Comments
shaikh-adil 16-Sep-12 13:06pm    
application.exit clashes which the form closing event when i palce in
e.cancle = false
application.exit()
So when a message box show. When i click yes it exits but when i click on NO. Then the same message box reappears twice.
I have tried so i asked another way.
: (
The code fragment you show reveals that, unfortunately, you have very little understanding on how to do programming. Note this mistake and don't repeat it: your if-else block is totally redundant.

You need to have something like this:
C#
//check "updated" status you always need to have, because this is something important
if (!updated) return; // no need to ask confirmation if no data was updated in UI
e.Cancel = (MessageBox(/* ... */) == DialogResult.No); //that's it: Boolean is assigned to Boolean


This won't answer your question, but this is because your answer does not have to be answered. The approach shown above works correctly; and it should work exactly like that under debugger (just because otherwise you would not know what are you debugging). You can always stop debugging via the IDE, which is the only right thing is you don't want to save file or continue execution with anything else.

—SA
 
Share this answer
 
Comments
shaikh-adil 17-Sep-12 6:04am    
i know. How much understanding i have.. I am not a software developer. I am a learner. Which is seeing this conding first time. So just give me some help neither your own coding.. How can i do that? I have my question just see and prefer some question relating to it
Sergey Alexandrovich Kryukov 17-Sep-12 20:08pm    
I think I already answered. What is not clear? What else do you need to understand? If you ask me this, I'll gladly answer.
Being a learning is a good thing, not a shame... :-) I wish you happy learning.
--SA
If you want to show the hidden form after closing the second form you can add this method to first form:

C#
public void ShowForm<T>() where T : BaseForm, new()
{
    T form = new T();
 
   form.FormClosed += delegate(object sender, FormClosedEventArgs e)
   {
       this.Show();
   };

   this.Hide();
   form.Show();
}


And call it in bottun_CLick;

C#
public void bottun_Click(object sender, EventArgs e)
{
    ShowForm<form2>();
}
 
Share this answer
 
v2
Comments
shaikh-adil 17-Sep-12 6:09am    
meysam you have understood my question.
My question is. When i have used this.hide in 1 form and 2 form then when i tried to close the 3 form. My debugging doesnt stops automatically. So. What to use? I have used form closing event. So i cant put application.close there because it over rides the event and the messagbox is shown twice when clicked on NO

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900