load form and passing parameters to it

  • Thread starter Thread starter Jared
  • Start date Start date
J

Jared

Hi
Does anyone know how could I load a form from another and send some
parameters to it?
Is there a way to identify by name instances of same form?
Thx
 
Jared said:
Hi
Does anyone know how could I load a form from another and send some
parameters to it?

A Form is just like any other class/object in .NET.

Create some private member variables and expose them as
properties with getters/setters.

In your FormA, create FormB and set the properties, and then
Show() the form.
Is there a way to identify by name instances of same form?

No. This is not VB6. There are types/objects and instances
of types/objects.

When you create an instance of FormB,you must maintain that
reference just like any other object, if you wish to call
methods, get/set properties, etc in the future.

-c
 
Jared said:
Does anyone know how could I load a form
from another and send some parameters to it?

Give your form a new constructor with parameters.

public Form1(string strTitle)
{
// Required for Windows Form Designer support
InitializeComponent();

this.Title = strTitle;
}

P.
 
Another option would be to create a parameterized constructor for the form.

Jeremy Wilde
 
to extend a bit:
What does referencing forms means to performance and
memory consumption? (If I have 10 forms loaded at once,and each of them
references one form and one or more classes,does this mean that each
referenced form and class is loaded into memory?)
 
Jared said:
to extend a bit:
What does referencing forms means to performance and
memory consumption? (If I have 10 forms loaded at once,and each of them
references one form and one or more classes,does this mean that each
referenced form and class is loaded into memory?)

If you have instances of a class or form created, then yes,
they take up memory.

Depending on how large your forms or classes are, this isn't
a lot of memory, really. Most classes are pretty small in
size. Forms are pretty small as well unless you have a lot
of embedded images and whatnot.

-c
 
Chad Myers said:
A Form is just like any other class/object in .NET.

It always amazes me the number of people who just don't seem to get
this. Personally I think the problem is that people dive straight into
Windows Forms without learning the basics first. I always recommend
learning a new language in the simplest way possible - which in C# is
by writing console apps. I'm sure if more people wrote console apps and
"played" with the language (and libraries) that way, they'd be less
confused when learning Windows Forms later.
 
Back
Top