Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Public Class1()
{
   this.FormClosing += OnFormClosing();
}

private void OnFormClosing(object Sender, EventArgs e)
{
   base.OnFormClosing(e);
   if (e.CloseReason == CloseReason.WindowsShutDown)
   {
      form_closing();//here i wrote my function to happen
   }
}

private void formcloasing()
{
   Class cls = new cls();
   cls.RemovefromOpenedChats((int)this.Tag);
}

Issue which I am facing:
No overload for method 'OnFormClosing' takes 0 arguments

Solution I need?
How to write a function in windows form while clicking red close(X) button?
Posted
Updated 4-Jun-13 20:23pm
v4

Try this:
C#
 protected override void OnFormClosing(FormClosingEventArgs e)
{
    //base.OnFormClosing(e);
    if (e.CloseReason == CloseReason.WindowsShutDown)
    { 
        //Do your stuff here
    }
}




--Amit
 
Share this answer
 
v2
Comments
riodejenris14 5-Jun-13 2:27am    
Then how to write a function while clicking the red close(X) button in the windows form?
_Amy 5-Jun-13 2:37am    
Please see my updated answer.
riodejenris14 5-Jun-13 2:38am    
thnx _Amy!!!
_Amy 5-Jun-13 2:49am    
You can hit "Accept Solution" button if it worked for you.
This is the method you are making call from private void OnFormClosing(object Sender, EventArgs e)
C#
private void formcloasing()
{
Class cls = new cls();
cls.RemovefromOpenedChats((int)this.Tag);
}


..and you're passing a parameter
C#
base.OnFormClosing(e);

Which is completely invalid.
 
Share this answer
 
Comments
riodejenris14 5-Jun-13 2:27am    
Then how to write a function while clicking the red close(X) button in the windows form?
Public Constructor_Class()
{
this.FormClosing+=OnFormClosing();
}
public void OnForm_Closing(object Sender,EventArgs e)
{
//your function;
}
 
Share this answer
 

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