mshvw

What code do I need to open an allready defined Form

I do not find any property like 'Form.Open()' or 'Form.Show()' or 'Form.Visible'....

Henk



Re: Windows Forms General How to open a Form?

Mark Dawson

Hi,

if you have a form like:

class MyForm : Form

{

}

You can open it by:

MyForm f = new MyForm();

f.Show() -> this is a non-modal form

f.ShowDialog() -> This is a modal form, the user must close it before they can use other forms in the app.

Mark.






Re: Windows Forms General How to open a Form?

mshvw

Thanks,

I have to get rid of Borland/VB habbits . When in Borland/VB a visual Form is created it can be immediately accessed without having to create an instance of it first!

To summarize for check:
So if I create a visual Form (MyForm) in the Microsoft Visual C# Express Edition (IDE) by menu:
'Project ->Add Windows Form -> MyForm -> Add'
then code 'MyForm->Show()' is not valid unless I first create an instance of this 'MyForm' by:
'MyForm f = new MyForm();'
and use
'f.Show();'

So by default a 'MyForm' instance is created and visible in the IDE but not accessible by the program.

Is that correct, although it seems very unlogical to me or is this the way Visual C# works

Henk





Re: Windows Forms General How to open a Form?

Mark Dawson

Hi,

behind the scene in the IDE an instance of the form is created so that you can modify it and design it. If you want to use that form type in your program then you will need to create an instance of it before hand in your code, this seems logical to me since you may want to create more than one instance of the form, dispose of the form to release resources then recreate at other times.

Mark.