Can-Ann

I have multiple forms that get loaded,

Can anyone correct this for me please

private void fnLoadForm( Form frmM)

{

Cursor.Current = Cursors.WaitCursor;

frmM frmS = new frmM();

frmM.ShowDialog();

}



Re: Windows Forms General Multiple Forms

Tom Meschter MSFT

Moving this to the Visual C# General forum, as it is not a question about the C# language per se.

It would also be helpful if you could describe the actual error or problem you are encountering.

-Tom Meschter
Software Dev, Visual C# IDE






Re: Windows Forms General Multiple Forms

Figo Fei - MSFT

Hi,

What the error is depends on where you put the codes and how you design the "frmM". The code itself is correct anyway.

Thanks






Re: Windows Forms General Multiple Forms

Andrej Tozon

Hi,

ShowDialog() method will show a form modally, that is, when calling your method (fnLoadForm), it won't return until the form (frmM) is closed. To load more forms at once with using your function, change ShowDialog() to just Show().

Andrej






Re: Windows Forms General Multiple Forms

Gabro

Andrej Tozon wrote:

Hi,

ShowDialog() method will show a form modally, that is, when calling your method (fnLoadForm), it won't return until the form (frmM) is closed. To load more forms at once with using your function, change ShowDialog() to just Show().

Andrej

sounds to me like he is already getting multiple forms loaded, which is not what he wants





Re: Windows Forms General Multiple Forms

Can-Ann

Correct Gabro, the problem is not to show modually or not, the problem is in passing the form info, which could be from the same project or another project.

The object is : a routine that will show the form passed to it.





Re: Windows Forms General Multiple Forms

Andrej Tozon

Are you passing a form instance to this function, or just its type

In the first case you don't have to initialize your form in the function, just show it. Try:

private void fnLoadForm(Form frmM)
{
   
Cursor.Current = Cursors.WaitCursor;
    frmM.ShowDialog();
}

If its just form's type, you'll have to use Activator.CreateInstance(type) to instantiate your form by its type.

Andrej






Re: Windows Forms General Multiple Forms

Can-Ann

I am passing an instance of the form - and that worked well thanks.