|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
string value to new form instance?Hi,
Suppose you had a listbox1 with 3 items; Form1 Form2 Form3 Now add an event handler for listbox1.selectedindexchanged in which you wish to create a new form instance depending on the value of the SelectedItem.ToString value. i.e. If "Form3" is clicked then a new instance of Form3 is created. Assuming your project contains a windows form called "Form3" - how is this achieved? Thanks in advance, Paul One way is through reflection:
Dim ExternalAssembly As System.Reflection.Assembly = _ System.Reflection.Assembly.LoadFrom(Container) Dim CalledForm As Form = _ ExternalAssembly.CreateInstance(FullName, True) CalledForm.FriendlyFormName = FullName CalledForm.Show() Where: Container is the name of the executable or dll containing the form (eg. "MyApp.Exe") FullName is the qualified name of the form (eg "MyApp.Form1") HTH Thanks BK that's exactly the kind of thing I was looking for! Just one Q
..... Having explored the assembly object for a while I still can't figure out how to find out through code the "Container" value you need in the LoadFrom method. For example, the Container value has a value of "XXX.exe" but the "FullName" needs a value of "XXX.Form1". I'm sure the GetExecutingAssembly method will prove useful but I'm struggling to pick out the correct way to do this. E.g. Let's say you have an class that is responsible for delivering form objects (dressed up with nice titles and styles etc) based on a string value equal to the form object name supplied to the constructor. This class could be called from anywhere in the solution. Thanks in advance, Paul Show quoteHide quote "BK" <bkunn***@hotmail.com> wrote in message news:1144870148.743645.127410@i40g2000cwc.googlegroups.com... > One way is through reflection: > > Dim ExternalAssembly As System.Reflection.Assembly = _ > System.Reflection.Assembly.LoadFrom(Container) > Dim CalledForm As Form = _ > ExternalAssembly.CreateInstance(FullName, True) > CalledForm.FriendlyFormName = FullName > CalledForm.Show() > > Where: > Container is the name of the executable or dll containing the form (eg. > "MyApp.Exe") > FullName is the qualified name of the form (eg "MyApp.Form1") > > HTH > Paul wrote:
Show quoteHide quote > Hi, Simpliest way:> > Suppose you had a listbox1 with 3 items; > Form1 > Form2 > Form3 > > Now add an event handler for listbox1.selectedindexchanged in which you wish > to create a new form instance depending on the value of the > SelectedItem.ToString value. i.e. If "Form3" is clicked then a new instance > of Form3 is created. > > Assuming your project contains a windows form called "Form3" - how is this > achieved? > > Thanks in advance, > > Paul > > in selectedindexchanged event: sub ... select case listbox1.selectedindex case 0 open form 1 case 1 open form 2 case else Nothing Selected end select end sub Now if you want to do it dynamically you are going to need to do this through reflection. You'll need to do a search like: http://www.google.com/search?hl=en&lr=&q=instantiate+a+class+from+string+vb.net+reflection&btnG=Search
How do I determine if a control has a specific property
i need timer interval more than 1 Minute. Class Inheritance Connection to Access Db with a password? AutoScroll listbox as I type DataGridView Send email throught VB.NET 2005 getting application version... Purpose of Keyword "Overloads"? Casting question |
|||||||||||||||||||||||