473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Apr 12 '06 #1
3 1408
BK
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

Apr 12 '06 #2
Paul wrote:
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


Simpliest way:

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&l...on&btnG=Search
Apr 12 '06 #3
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

"BK" <bk******@hotmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.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

Apr 14 '06 #4

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

Similar topics

4
by: Andrew Chalk | last post by:
I am a raw beginner to Python. I just read in "Learning Python" that assigning to a string argument inside a function does not change the string in the caller. I want an assignment in the function...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
6
by: Chris Simmons | last post by:
I know that a String is immutable, but I don't understand why this piece of code fails in nUnit: // BEGIN CODE using System; class Test { public static void Main( String args )
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: scorpion53061 | last post by:
I have little hope of resolving this as I have had to contact outside help. But I thought I would post it here to see if anyone could add an idea or solution. 1. I have a form in a Class...
3
by: Ann Huxtable | last post by:
I wrote a method that accepted a form. The signature was as ff: void foo(ref Form frm) ; I had to remove the ref keyword to get it to compile. Any idea why? I though forms would be passed by...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
4
by: robtyketto | last post by:
Greetings, I'm a newbie to Java and I cant quite get my head around why it seems most integers appears to be formatted as strings and then later have to be parsed. The code below, passes in the...
10
by: jimjim | last post by:
HI, We have shifted our database from sqlserver2003 to sqlserver2005. 1. connection strings stored in web.config <!-- Machine name to connection string keys --> <add key="*777*"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.