Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Using Reflection.Assembly to Load Forms
Author:
Syed Irtaza Ali
E-mail:
Click to e-mail author
Website:
http://www.edreamz.net
Submitted:
2/14/2005
Version:
VB.NET 2003
Compatibility:
VB.NET 2003
Category:
Forms
Views:
26920
=============================================== This code sample is going to make your day. The scenario where this code could be quite helpful is where you are fetching a form name from the database and would like to open that form by passing the name as a string variable. To accomplish this task you will have to use the System.Reflection.Assembly class. Note that the form name in the textbox should include its complete namespace. For example, "Project1.Formname" or "Inventory.frmItem".
Declarations:
using System.Reflection;
Code:
// [C#] try { Assembly myAssembly = Assembly.GetExecutingAssembly(); Form myForm = myAssembly.CreateInstance(txtFormName.text) as Form; myForm.ShowDialog(); } catch (System.NullReferenceException exNull) { MessageBox.Show ("Invalid Form name. Please note that Form names " + "are case sensitive.", "Form not found"); System.Diagnostics.Trace.WriteLine("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" + Environment.NewLine + "Project Load" + Environment.NewLine + exNull.ToString()); } catch (Exception ex) { MessageBox.Show (ex.ToString()); }
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement