473,574 Members | 3,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opening form by name

Hi;

is it possible to open one form in .net platform that we have its name in
string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..

Nov 15 '05 #1
11 12788
Well, a variable name (including a form name) is very different from a
string, but you could always do this:

if (sFormName = "frmCustome r")
FormCustomer.Sh ow();
else if (sFormName = "blah")
FormBlah.Show() ;
else if (sFormName = "blither")
FormBlither.Sho w();

....etc.
"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi;

is it possible to open one form in .net platform that we have its name in
string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..


Nov 15 '05 #2

thnaks.

I have number of forms and all names are written on database to be opened.
so I must find an automatic way

what about fro form items ?
do I have to search every item in Controls list by name or
can I find one item by name like hash

"Michael A. Covington" <Mi*****@Coving tonInnovations. com> wrote in message
news:uj******** *******@tk2msft ngp13.phx.gbl.. .
Well, a variable name (including a form name) is very different from a
string, but you could always do this:

if (sFormName = "frmCustome r")
FormCustomer.Sh ow();
else if (sFormName = "blah")
FormBlah.Show() ;
else if (sFormName = "blither")
FormBlither.Sho w();

...etc.
"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi;

is it possible to open one form in .net platform that we have its name in string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..



Nov 15 '05 #3
There are several ways to instantiate a class dynamically. You can check
out the Reflection APIs or the Activator class. Once the object is created,
you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
Hi;

is it possible to open one form in .net platform that we have its name in
string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..


Nov 15 '05 #4

thanks for your help;
i think activator class will work

but I cant add activator functions to project.
compiler says System.Activato r does not exist

Can you please help me with how to use activator class.


"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
There are several ways to instantiate a class dynamically. You can check
out the Reflection APIs or the Activator class. Once the object is created, you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
Hi;

is it possible to open one form in .net platform that we have its name in string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..



Nov 15 '05 #5

thanks for your help;
i think activator class will work

but I cant add activator functions to project.
compiler says System.Activato r does not exist

Can you please help me with how to use activator class.


"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
There are several ways to instantiate a class dynamically. You can check
out the Reflection APIs or the Activator class. Once the object is created, you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
Hi;

is it possible to open one form in .net platform that we have its name in string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..



Nov 15 '05 #6
search on 'using'
"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:uX******** ******@TK2MSFTN GP10.phx.gbl...

thanks for your help;
i think activator class will work

but I cant add activator functions to project.
compiler says System.Activato r does not exist

Can you please help me with how to use activator class.


"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
There are several ways to instantiate a class dynamically. You can check
out the Reflection APIs or the Activator class. Once the object is

created,
you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
Hi;

is it possible to open one form in .net platform that we have its name

in string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..




Nov 15 '05 #7
Could you post a small repro of your problem. When I try something like the
following, I can compile.

object act = Activator.Creat eInstance(typeo f(string), null);

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:uX******** ******@TK2MSFTN GP10.phx.gbl...

thanks for your help;
i think activator class will work

but I cant add activator functions to project.
compiler says System.Activato r does not exist

Can you please help me with how to use activator class.


"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
There are several ways to instantiate a class dynamically. You can check
out the Reflection APIs or the Activator class. Once the object is

created,
you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
Hi;

is it possible to open one form in .net platform that we have its name

in string ?

I have
string sFormName = "frmCustome r";
and I must automatically open Customer form.

or is it possible to get one referance of an item on form ?
i mean,
ctrlText = xxxx("textBox1" );
ctrlText .Enabled = false;

thanks..




Nov 15 '05 #8
Should not matter. I beleive that Activator is part of the System namespace
in the mscorlib assembly.

"james" <no****@hyperco n.net> wrote in message
news:eN******** ******@tk2msftn gp13.phx.gbl...
search on 'using'
"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:uX******** ******@TK2MSFTN GP10.phx.gbl...

thanks for your help;
i think activator class will work

but I cant add activator functions to project.
compiler says System.Activato r does not exist

Can you please help me with how to use activator class.


"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
There are several ways to instantiate a class dynamically. You can check out the Reflection APIs or the Activator class. Once the object is

created,
you can simply use the standard methods such as Show().

"Ahmet AKGUN" <ak*********@ho tmail.com> wrote in message
news:e4******** ******@TK2MSFTN GP09.phx.gbl...
> Hi;
>
> is it possible to open one form in .net platform that we have its
name in
> string ?
>
> I have
> string sFormName = "frmCustome r";
> and I must automatically open Customer form.
>
> or is it possible to get one referance of an item on form ?
> i mean,
> ctrlText = xxxx("textBox1" );
> ctrlText .Enabled = false;
>
> thanks..
>
>
>
>
>



Nov 15 '05 #9
Dear Ahmet,

.NET contains all sorts of stuff to play around with types, forms and
variables and stuff without knowing too much about them. If you know the
name of a Type in .NET you can find out anything about it, create instances
of it and set values, execute methods, etc, etc. This is all given by the
System.Type and System.Reflecti on namespaces. It's wonderful!! :-)

When you look at the help info on these it's daunting to say the least.
It is however very simple once explained.

Your problem as I understand it is that you have various form names in a
database and you want to get these forms up and running with only the name
as your starting point. No problem using Reflection :-)

A form's name is it's class name. And a class name is a Type name. Or
near enough. Let's say you have a form called frmFoo. And this is defined in
your application's namespace which will be something like Akgun.WonderApp .
The full type name of your form will therefore be Akgun.WonderApp .frmFoo.
Now if you plug that name, as a string, into Type.GetType(), you'll get a
Type object - which is something that you can use to create an instance of
the form.

So:
sFormName = <Obtain form name from database>;
Type oFormType = Type.GetType ("Akgun.WonderA pp." + sFormName);

Now the next part depends on whether your forms' constructors have
parameters or not.

If there are no parameters, ie. you have simply
public frmFoo() {
InitializeCompo nent();
: : :
}

then you can get your form up in one (complex) line.
((Form) oFormType.GetCo nstructor (System.Type.Em ptyTypes).Invok e
(null)).Show(); // Display form..

Let's break this down. This is the long version:
ConstructorInfo oConstructorInf o = oFormType.GetCo nstructor
(System.Type.Em ptyTypes);
Form oForm = (Form) oConstructorInf o.Invoke (null);
oForm.Show();

Every Type can provide, amongst many things, information about the
constructor or constructors that are available with the type.
GetConstructor( ) takes an array of the Types of the arguments to the
constructor - part of its "signature" - with which it matches against all
the constructors for that type. System.Type.Emp tyTypes is simply an empty
Types array signifying that we want the constructor with no parameters.

Having got the constructor info object, we can ask it to create an
instance of the type that it knows about - in this case the required form.
That's the job of Invoke() and the null is there because the constructor
takes no arguments. The value returned is an instance of your form which is
cast and assigned to a Form variable.

Form oForm = (Form) oConstructorInf o.Invoke (null);
is the equivalent of
Form oForm = new frmForm()
except, of course, that frmFoo is not mentioned anywhere.

Ok. That's how it works if you have no arguments for your form's
contructor. In case there are args, and for anyone interested, here's a more
complex version.

Let's say that this time we're dealing with frmBar which has the
following constructor
public frmBar (integer i, double d) {...}

This time we can't use a one-liner to do the job:

Type[] aoArgTypes = new Type[2] {Type.GetType ("System.Int32" ),
Type.GetType ("System.Double ")}; //Fussy about names.
ConstructorInfo oConstructorInf o = oType.GetConstr uctor
(aoArgTypes);
Object[] aoArgs = new Object[2] {(System.Int32) 1, (double) 2};
//Not fussy.
Form oForm = (Form) oConstructorInf o.Invoke (aoArgs);
oForm.Show();

You'll see in the second line that we are again getting a constructor
info object. But this time we actually have some arguments which must be
specified. That's done in the first line and you'll notice that while frmBar
takes an integer, GetType() requires a string containing the full .NET name,
"System.Int 32". Likewise for double.
The third line creates an array corresponding to the array of types, but
this time with the actual argument values. This array is then given to
Invoke() so that the constructor has some values to play with.

Easy, huh?

I would recommend having form constructors with no arguments because
that makes it dead simple using the first example. Having arguments will
involve storing type names and values in the database and packaging them up
for GetConstructor( ) and Invoke(). Nah, don't want to bother with that,
thanks.

A final note. Hard-coding "Akgun.WonderAp p." is not best practice. As
your empire expands, you might change the namespace to
Akgun.Apps.Data base.WonderApp and forget to change the corresponding string.
It's possible to get the name from the assembly. I'll leave that as an
exercise.

Best wishes,
Fergus.
Nov 15 '05 #10

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

Similar topics

3
1705
by: Display Name | last post by:
When this form's being submitted, two windows are opening instead of only one here is the function I'm using: function subForm(){ //insert form validation here //if form is valid, open a pop-window & submit subWin = window.open("http://www.smoochya.com/books.html","subWin","width=550,height= 350,address=no")
9
1289
by: BLUE WATER | last post by:
Help, When I am finished entering in data into my form A, I press the save button that saves this new data to a new record. However I would like my other form to open at a specific record, the record that I just finished working on. Ideas?
3
2119
by: Rolan | last post by:
I need assistance regarding code needed to prevent someone from opening a form if a table field name(s) has been changed. For example, there is existing code to check for certain data based on DLookup in a table before a form can be opened. If one changes the field name in the table, then the verification check is bypassed. So adding code to...
1
9753
by: kevcar40 | last post by:
hi is it possible to stop a form opening if the result of the query is null? eg select a company name from a combobox if the name is not in the table (ie the query returns null) can i stop the form opening thanks
1
1458
by: paintedjazz | last post by:
I am using the following javascript to make a popup menu allow the user to navigate to different pages on a website. Yet it is opening windows as if I have <base target="some-name"> defined in the body. <script language=javascript> <!-- Begin function navigate() { open(document.popupForm.popup.options
0
1035
by: KavithaSing | last post by:
Hi everyone, In our website we have an option ‘official login’ for users to login and send information through the site. We face the following problem while loggin in. We use the following sequence. From the home page, index.html, a hyperlink on ‘official login’ will open the page testlogin.htm. In the testlogin.htm, we get userid and...
1
1315
by: deararuns | last post by:
i hav a window wit a button and text box.. Then am opening a new window... suppose if i type somethin in a first window's text box.. and click the button.. the value typed in the text box shoult appear in the opening window... Is it possible <html> <body> <script type = "text/javascript"> function fun1 ( )
16
5163
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub Storage_Click() On Error GoTo Err_Storage_Click
2
2302
by: John | last post by:
Hi I have a number of forms which open like this; Dim frm1 As frmForm1 = New frmForm1 Dim frm2 As frmForm2 = New frmForm2 Dim frm3 As frmForm3 = New frmForm3 Dim frm4 As frmForm4 = New frmForm4 .....
1
2001
by: geetamadhavi | last post by:
Hi All, I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i even tried with echo also how to solve this the message should come under in the same window only see my code it is program ---- <?php //...
0
7841
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7760
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5654
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5335
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1099
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.