|
-
Sep 26th, 2003, 03:51 PM
#1
Thread Starter
Member
Run a Form with a String Variable
Hi All,
I have multiple forms created and my question is if it is possible to show a from via a string variable, something like this.
Normal:
Dim frmtest As New frmRegistry
frmtest.ShowDialog()
Something like this:
dim runform as string = "frmRegistry"
Dim frmtest As New runform
frmtest.ShowDialog()
Or should I do this on another way.
Thanks,
AXH
-
Sep 26th, 2003, 03:59 PM
#2
Yes you can use the Activator.Createinstance method to create objects from strings, but the string has to be the full namespace.
VB Code:
'if you have option strict on then you may have to declare it as an object instead of form
Dim frm As Form=Activator.CreateInstance("MyNamespace.frmregistry")
frm.ShowDialog
Here is an example from MSDN: http://msdn.microsoft.com/library/de...et10082002.asp
-
Sep 26th, 2003, 04:14 PM
#3
Thread Starter
Member
This is the error message:
Value of type 'String' cannot be converted to 'System.Type'.
With the following code:
Dim frmname As String = "frmRegistry"
Dim frm As Form = Activator.CreateInstance(frmname)
frm.ShowDialog()
-
Sep 26th, 2003, 04:20 PM
#4
As I said the string must be the full name of the object including namespace. Try reading the MSDN article for more information.
Your project automatically has at least a root namespace so 'frmRegistry' is not the full name of the form.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|