Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hii,everyone

i find the solution here :
but i need to pass this code ( class_Exit ex = new class_Exit();
ex.exituni();) to unify the message box that will appear when close by close icon or button close

C#
protected override void OnFormClosing(FormClosingEventArgs e)
 {     base.OnFormClosing(e);
      if (e.CloseReason == CloseReason.WindowsShutDown) return; 
     // Confirm user wants to close  
   switch (MessageBox.Show(this, "Are you sure you want to close?", "Closing", MessageBoxButtons.YesNo)) 
    {  
   case DialogResult.No:   
      e.Cancel = true; 
        break;  
   default:
         break;
   
  }
         }
Posted
Updated 17-Sep-12 0:29am
v5
Comments
Philip Stuyck 13-Sep-12 1:40am    
aren't the form closing and close event suitable for this ?
mhassan083 13-Sep-12 3:30am    
the code i need to write ( exitClass ex = new exitClass();
ex.exituniversal();)
how this code write to close icon that is appear in the form design.
and when click close icon work like code in button that display message alert..
Karthik Harve 13-Sep-12 1:41am    
What exactly are you tring to do ? if possible show the code you tried.

Hi ,
Check this
C#
   class ClsClose
    {
        Form frm = new Form();
       public  ClsClose(Form _frm )
        {
            frm = _frm;
        }
       public void CloseForm()
       {

           frm.Close();
       }
    }
          //Form
        private void button1_Click(object sender, EventArgs e)
        {
            ClsClose cls = new ClsClose(this);
            cls.CloseForm();
        }



this.Close();
//or 
Application.Exit();


Best Regards
M.Mitwalli
 
Share this answer
 
v2
Comments
mhassan083 13-Sep-12 3:00am    
thanks eng Mohamed ,but the code i need to write ( exitClass ex = new exitClass();
ex.exituniversal();)
how this code write to close icon that is appear in the form design
Mohamed Mitwalli 13-Sep-12 3:13am    
You mean u need your own class that responsible for closing Form
mhassan083 13-Sep-12 3:26am    
yes ,when its code write to work in close icon in windows form
Mohamed Mitwalli 13-Sep-12 3:38am    
Check the Update solution
But why you want to do it like this :-/
mhassan083 13-Sep-12 6:10am    
eng,Mohamed i'm already prepare code that i used by create class that include method used by call in any button i'm success in it, the same code where i put that
when click in the close icon will make the same results that code in button make also.
C#
//Icon Event
     private void Icon_Click(object sender, EventArgs e)
        {
            exitClass ex = new exitClass(); 
            ex.exituniversal();
        }
 
Share this answer
 
Comments
mhassan083 13-Sep-12 6:14am    
How to call this method,and where i write ,i'm beginner
joje1985 13-Sep-12 6:49am    
go to msdn site there you will find lots of tutorials regarding controls of .NET see it.
why ur writing code for to handdle close button ,just set form 'control box' property set to false.
 
Share this answer
 
Comments
mhassan083 13-Sep-12 3:02am    
the code i need to write ( exitClass ex = new exitClass();
ex.exituniversal();)
how this code write to close icon that is appear in the form design.
and when click close icon work like code in button that display message alert.

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