473,385 Members | 1,445 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,385 software developers and data experts.

Open Form in C# knowing Name Only

Hi,

I asked a question a few days ago that wasn't clear enough. I need to open
a form in a C# project, but I know only its name.
I guess I should look into Reflexions to do this, but it doesn't work for me
yet. I am using the following code:

string assemblyName = "WindowsApplication1";
string typeName = "WindowsApplication1.Test";
object o = Activator.CreateInstance(assemblyName, typeName, null);
((Form)o).Show();

I have a System.TypeLoadException in mscorlib.dll on line 3. What I am
missing there?

Thanks

vbdev
Nov 17 '05 #1
2 5556
If this code is running from within WindowsApplication1, I would do the
following instead:

object o =
Assembly.GetExecutingAssembly().CreateInstance("Wi ndowsApplication1.Form1");
((Form) o).Show();

If you are using remoting in any way please disregard my response, this code
is only running good locally.

--
Francisco Padron
www.chartfx.com
"vb6dev" <vb********@hotmail.com> wrote in message
news:OY*************@TK2MSFTNGP12.phx.gbl...
Hi,

I asked a question a few days ago that wasn't clear enough. I need to
open a form in a C# project, but I know only its name.
I guess I should look into Reflexions to do this, but it doesn't work for
me yet. I am using the following code:

string assemblyName = "WindowsApplication1";
string typeName = "WindowsApplication1.Test";
object o = Activator.CreateInstance(assemblyName, typeName, null);
((Form)o).Show();

I have a System.TypeLoadException in mscorlib.dll on line 3. What I am
missing there?

Thanks

vbdev

Nov 17 '05 #2
Hello,
Try using
object o = Activator.CreateInstance(typeof(WindowsApplication 1.Test));
((Form)o).Show();

HTH, Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3

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

Similar topics

2
by: monika | last post by:
Hi all... I am able to select a student's story and open it in a word doc. the teacher then corrects the story, highlight in colors the comments, strikethrough. In fact all the privileges I...
4
by: James Bond 007 | last post by:
I am a novice to Javascript (can do simple text-based pop-ups, but not familiar with variable manipulation). I would like to have a Javascript that gives me the start time (I don't care about...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
6
by: Kenneth Courville | last post by:
Hello, I'm looking for assistance with the Access object model. I know this is VB, but I'm building an Office Add-using C# directed at Access 2002. I'm literate in VB, so you can reply in VB... I...
11
by: Ahmet AKGUN | last post by:
Hi; is it possible to open one form in .net platform that we have its name in string ? I have string sFormName = "frmCustomer"; and I must automatically open Customer form. or is it...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
4
by: Jon Davis | last post by:
Newbie to WCF here. I am getting the error "unable to open its IChannelListener", but the service is running as an admin, and on a different port from anything else. If it matters, I'm trying to...
19
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization...
14
by: SimeonD | last post by:
Hi I have an access database called Sales.Mdb In vb.net 2005, I'd like to open it. Which I can do. What I can't figure out is how to figure out if Sales.Mdb is open already. If so, I want to open...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.