473,406 Members | 2,816 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,406 software developers and data experts.

VB.NET Forms access via Form Name at Runtime

Ian
Hi,

If I have created several forms in my VB.NET app called Form1, Form2, Form3
etc can I instantiate a form via its name.

So if I enter the form's name in a textbox can I have that form appear?

Thanks
Ian
Nov 20 '05 #1
4 1390
* "Ian" <ba********@canada.com> scripsit:
If I have created several forms in my VB.NET app called Form1, Form2, Form3
etc can I instantiate a form via its name.

So if I enter the form's name in a textbox can I have that form appear?


\\\
Dim objNewForm As Object = _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
)
Dim frm As Form = DirectCast(objNewForm, Form)
frm.Show()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
You could do this sort of thing...

\\\
Private Sub textbox_Leave(ByVal sender As Object, ByVal e
As System.EventArgs) _
Handles txtTextbox.LostFocus

If txtTextbox.text = "form1" Then
Dim objForm1 As New frmForm1
Me.frm1.showdialog()

ElseIf txtTextbox.text = "form2" Then
Dim objForm2 As New frmForm2
Me.frm2.showdialog()
End If
///

obviously you don't have to use LostFocus but can instead
use an other of the textboxes methods to trigger the event
Nov 20 '05 #3
Hi Steven,

* "Steven Smith" <an*******@discussions.microsoft.com> scripsit:
\\\
Private Sub textbox_Leave(ByVal sender As Object, ByVal e
As System.EventArgs) _
Handles txtTextbox.LostFocus

If txtTextbox.text = "form1" Then
Dim objForm1 As New frmForm1
Me.frm1.showdialog() ^^^^^^^

.... should read 'objForm1'.
ElseIf txtTextbox.text = "form2" Then
Dim objForm2 As New frmForm2
Me.frm2.showdialog()
End If
///


Little note:

You can 'save' a variable:

\\\
Dim f As Form
Select Case txtTextBox.Text
Case "Form1"
f = New Form1()
Case "Form2"
f = New Form2()
Case ...
...
...
End Select
f.ShowDialog()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"Ian" <ba********@canada.com> schrieb

If I have created several forms in my VB.NET app called Form1, Form2,
Form3 etc can I instantiate a form via its name.

So if I enter the form's name in a textbox can I have that form
appear?


It is possible but I think the user is not interested in the names the
developer has chosen as the class name of a form.

If you really need it, have a look at Activator.Createinstance.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

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

Similar topics

7
by: Bob Nolty | last post by:
Hi all -- I'm trying to create a hidden form in the document using only Javascript -- I don't know what form I want until the user clicks a button -- I tried the following code, which does...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
3
by: brett | last post by:
Using DOM in IE, how can I loop through FORMs and access FORM elements in a specific form? For example, www.hotmail.com has about 13 forms. I believe the one displayed is dependent on the URL. If...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
12
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I have the following code ... Dim frmLink As Form Set frmLink = Forms.Add(stringformname) frmLink.Show 'wait until all data has been loaded Do Until frmLink.Loaded = 21 DoEvent
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.