Error in calling a method

Dear all

good day

i ve 1 question, i make a function that open a form from another

the method is as follows

public static void DisplayForm(Form targetForm)

{

targetForm.Show(targetForm);

}

instead the classic way

Form2 frm = new Form2();

frm.Show();

it have one parameter and it has from data type, when i call this function it fire the following error

DisplayForm(Form2);

'Form2' is a 'type' but is used like a 'variable’

kindly instruct

thanks all




Answer this question

Error in calling a method

  • GoldRunner

    Dear Christian Graus

    thanks for your speedy replay, your explaination was very useful

    and i will act accordingly

    yours very truly

    Mohamed Sakr



  • Sreekk

    The error is correct. You COULD do this:

    DisplayForm(new Form2)

    but to be honest, I can't see any use in having this method at all. Apart from anything else, you call a method that just calls another method, what's the use of that Plus you're not keeping a refrence to a modeless form, which is a bad move.

    //targetForm.Show(targetForm);

    I did not know there was an overload to Show which took a form as a parameter I hope it's not to set the parent, a form can't be it's own parent.



  • Jo_

    No problem - always glad to help out ...



  • Error in calling a method