Open a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I Want to open a form that a user specify in a textbox...
Thereis any way to open a form having justt only is name?

Ex: txtForm.Text = "frmSomething"
Form oform= new (Form)txtForm.Text.ToString();
oform.open();
 
Hi,

Here's an example (not tested though):

Form oForm = (Form)System.Reflection.Assembly.CreateInstance(
txtForm.Text);
oForm.Show();

NOTE: The example assumes the form to be created resides in the same
assembly that
contains the code above.
 
From the docs on the Activator class:

ObjectHandle hdlSample;
IMyExtenderInterface myExtenderInterface;
object[] activationAttributes = {new SynchronizationAttribute()};

// Assumes that SampleAssembly.dll exists in the same directory as this
assembly.
hdlSample = Activator.CreateInstanceFrom("SampleAssembly.dll",
"SampleNamespace.SampleClass", activationAttributes);

// Assumes that the SampleClass implements an interface provided by
// this application.
myExtenderInterface = (IMyExtenderInterface)hdlSample.Unwrap();


All you need to do is replace "IMyExtenderInterface" with "Form" since all
Forms inherit from that class, and ofcourse use the correct assemblyname and
classname.



Arild
 
Hi

This cod
Form oform = (Form)System.Reflection.Assembly.CreateInstance(txtNomeEcran.Text)

raises an error:
An object reference is required for the nonstatic field, method, or property 'System.Reflection.Assembly.CreateInstance(string)

Can you help
Thanks a lot
 
=?Utf-8?B?QmVybmFyZG8=?= said:
This code
Form oform = (Form)System.Reflection.Assembly.
CreateInstance(txtNomeEcran.Text);

raises an error:
An object reference is required for the nonstatic field, method,
or property 'System.Reflection.Assembly.CreateInstance(string)'

Can you help?

Yes - you need to specify *which* assembly to use to create the
instance. You're using it as if CreateInstance were a static method,
which it's not.
 
Back
Top