Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / November 2004

Tip: Looking for answers? Try searching our database.

How to dynamically create an instance of a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Harshad Rathod - 29 Nov 2004 00:07 GMT
Ususally we do like:

SalesOrderForm fm = new SalesOrderForm();

where SalesOrderForm is a valid form in one of the assembly, that is
SalesOrderForm is a type.  How can I create an instance of SalesOrderForm
when I do not know its type at run tyme?  For example

public openForm (string formName)
{
  // here I might get "SalesOrderForm" or something else.  If I get  
"SalesOrderForm" then I want to open it.  
Here, it will also be NOT known which assembly this for is in.
}

Thanks.
Christoph Wienands - 29 Nov 2004 21:02 GMT
Hi Harshad,

> Ususally we do like:
>
[quoted text clipped - 3 lines]
> SalesOrderForm is a type.  How can I create an instance of SalesOrderForm
> when I do not know its type at run tyme?  For example

Runtime or design time? At runtime you'll have to know what and where, how
else would you be able to create the form.

> public openForm (string formName)
> {
>    // here I might get "SalesOrderForm" or something else.  If I get
> "SalesOrderForm" then I want to open it.
> Here, it will also be NOT known which assembly this for is in.
> }

If the form name contains all the information about assembly name and form
name you can use reflection to create that type. Don't know out of my head
how to do that but reflection is the thing to look at. .Net assemblies can
be registered in the GAC with a strong name, alternatively you can make them
accessible through COM (automatic COM wrapper). Then you could create a form
of type "MyAssembly.MyForm".

Hope this helps,

Christoph

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.