473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Windows Forms at runtime using System.Reflecti on

Hi,

I'd like to know if it is possible to create a form type from a string. My
case: I have a DataTable with forms names (i.e frm_001_UserInf o.cs), and I'd
like to create an instance of that form from my code dynamically, retrieving
the form name from the database.

Something like str = "frm_001_UserIn fo.cs" and then create an instance of
the form using str.

For what I've read about System.Reflecti on, there might be a way to do this,
but I dont know how.

Any help would be greatly appreciated.

Thanks in advance.
Nov 16 '05 #1
3 4372
hi
i think this article on the MSDN can help a lot

http://msdn.microsoft.com/library/de...us/dnadvnet/ht
ml/vbnet10082002.a sp
Hope it does
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
u can use
System.Reflecti on.Assembly.Get ExecutingAssemb ly().CreateInst ance(formName)

and pass in your form name. but make sure that your form type exists in the
current assembly. If not, you have load the assembly that contains the form
and create an instance of that form.

hth

"Bisbal" <Bi****@discuss ions.microsoft. com> wrote in message
news:87******** *************** ***********@mic rosoft.com...
Hi,

I'd like to know if it is possible to create a form type from a string. My
case: I have a DataTable with forms names (i.e frm_001_UserInf o.cs), and I'd like to create an instance of that form from my code dynamically, retrieving the form name from the database.

Something like str = "frm_001_UserIn fo.cs" and then create an instance of
the form using str.

For what I've read about System.Reflecti on, there might be a way to do this, but I dont know how.

Any help would be greatly appreciated.

Thanks in advance.

Nov 16 '05 #3
Mohamoss,

I use:

Dim GenericInstance As Object
GenericInstance = Activator.Creat eInstance(TypeT oLoad)

Dim FormToShow As Form = CType(GenericIn stance, Form)

from the example to load a form that does not has parameters in its
constructor, everything work fine.

However, some of our forms need input parameters for the constructor, so I
use the following code:

Dim frm() As Form = {Me} ' Me is the calling form
Dim formActivator As Object = Activator.Creat eInstance(formO bject, frm)

I keep getting the following error message at the above line:

"An unhandled exception of type 'System.Argumen tNullException' occurred in
mscorlib.dll. Additional information: Value cannot be null."

Do you have any ideas what happen

Thanks

DavidT

"Mohamoss" wrote:
hi
i think this article on the MSDN can help a lot

http://msdn.microsoft.com/library/de...us/dnadvnet/ht
ml/vbnet10082002.a sp
Hope it does
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6407
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this to happen we had to change the context in which asp.net runs from machine to SYSTEM by modifying the machine.config file. Under Windows 2003 no matter how asp.net is set to run as either machine or system. I get the following error: ...
0
600
by: Matt Warner | last post by:
Hi guys, A couple of people have already posted questions about similar issues but haven't had any response. Occasionally, sometimes after running the app for a few hours, it bombs out saying that it could not create a windows handle. On one machine the stacktrace is this:
0
2155
by: Sinisa | last post by:
I have a Windows form which has multiple groups of the same window controls. I wanted to create a control class that has the standard controls in one. something like: public class Sensor : System.Windows.Forms.Control { private System.Windows.Forms.TextBox Calculation;
2
6610
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in advance -Hari
9
2822
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
5
3382
by: Steve Teeples | last post by:
Can someone point me to a document that clearly identifies the steps of creating a good help system for an application? I have a test tool that I'd like to add help to so that others will know how to use it. -- Steve
15
6750
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use javascript or vbscript it works. I will appreciate any help. I do the following (C#):
6
1919
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create a new thread to display a customer on the screen for example. However, I have a problem with circular references in my objects which means that I have to load the customer object using reflection ie :
8
7940
by: J.S. | last post by:
I was under the impression that frames could be used in Windows forms in earlier version of VB. However, in VB 2005 Express I don't see any such tool/control. Is SplitContainer used for this purpose in VB 2005? I want to create a frame in a Windows form because I'd like button clicks on the left side of the form to change the form elements shown in the right side of the form. Would each of the buttons on the left require a...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.