You are using the namespace-qualified name, correct?

If you have code like this (sorry, don't sprechen sie VB)

namespace Accounts
{
        public class AccountForm : Form
        {
                // ....
        }
}

Then this code will create an instance of it:

string sFormName = "Accounts.AccountForm";
Type t = Type.GetType(sFormName);
Form f = (Form) Activator.CreateInstance(t);

Works like a champ for me...

HTH,

Seang

-----Original Message-----
From: Dan Souk [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 23, 2002 2:05 PM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] AW: [DOTNET] AW: [DOTNET] Load Form by Name


It's your code:)

01 Dim ty As Type =
System.Reflection.Assembly.GetExecutingAssembly.GetType(strFormName)
02 Dim frm As System.Windows.Forms.Form = Activator.CreateInstance(ty)

The exception raised is System.ArgumentNullException, raised on line 02
above. The variable ty is Nothing.

Other notes:
-The form in question (call it frmA) does exist in the GUI project. The
class is public.
-frmA inherits from a base form (call it frmB), also present in the GUI
project.
-Casting obviously isn't the issue at this point because ty is nothing.
-The form is in the GUI layer of the solution, and other projects
(interfaces, data tier, business objects) are also present. Any chance
GetExecutingAssembly is looking in the wrong assembly?




-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of
Urs Eichmann
Sent: Tuesday, April 23, 2002 2:40 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET] AW: [DOTNET] AW: [DOTNET] Load Form by Name


> I found the Activator class a little while ago and played around with
> it, but no luck. Seems that the type info is available, but
> Activator.CreateInstance doesn't create an instance of the form.

It DOES create an instance of the form! I use this technique myself for
loading forms dynamically. What does it do in your case? Is there an
exception thrown? Perhaps you should show us the code you use.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to