Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I was wondering if there was a way to dynamically load a form with a function similar to the following:

 

function openform(formName as string) as form
   dim f as new form
   'some code here to open what ever form is named "formName"
   return f
end function

Go Beavs!!!
  • Leaders
Posted
What would you be using this for? Where is the string coming from? You may find a select case to be the easiest route. If you need to be a little more dynamic, the Assembly class is probably the solution. Things can get tricky if you aren't sure which assembly the type belongs to, so if you are using this for some sort of plug-in system or anything along those lines, a System.Type might be a little more approprite. And then, if you need to serialize type info, the Type.AssemblyQualifiedTypeName and Type.GetType functions come in handy.
[sIGPIC]e[/sIGPIC]
Posted

I have a dynamically built form that adds a series of buttons. each button loads a specific form. Each button is defined by a database record. I currently am using a case statement to determine which form to load, but that has to be coded everytime something new is added.

 

I would like the button to automatically open the form defined by the database record.

Go Beavs!!!
Posted

Forget what I said.

 

Either way you do it...you have to have a way to relate the form to the id you give it in the database.

 

If not a select case...a config file....an enumeration

All will have to be updated each time a new form is created

 

if you use activator.createinstance...what are you going to use to define the form? are you going to keep the actual class name in the database?

  • Leaders
Posted

Activator.CreateInstance can take a System.Type, which can be created from an assembly-qualified type name. If you have an assembly-qualified type name in the DB, you can pull it and instantiate it without having to worry about which assembly it belongs to (assuming that the assembly is loaded).

 

If the forms are all in the same assembly and you know which assembly they are in then make life easier and just use PD's suggestion.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...