Closing a specific form using a method in C #

Hi, I have some forms in my project, and I want to make a method that closed one of them. Method:

public static void close_form (Form frm)
{
    frm.Close();
}

And I use it like this:

public partial class myForm : Form
{
   close_form(myForm);
}

but when I want to run the application, I get the error: myFormis a "type", but is used as a "variable"

What am I doing wrong? Is there any other way to closeform without using this.close()?

+5
source share
1 answer

You pass the type of form, i.e. myFormyou need to pass an object of type you can passthis

public partial class myForm : Form
{
   close_form(this);
}

myForm - , Form . this , close_form, .

, , , , , , , , .. this.Close close_form .

+8