470,593 Members | 2,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,593 developers. It's quick & easy.

creating a vb.net project with multiple forms

Don
hi

in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now i'm using vb.net (still getting used to it) and can not figure out how to hide and show forms. my project presently has a few forms but i can only the startup form is visible. i can't hide the startup form or show the other forms. i would like to hide a form when a button is pressed and then show another

thanks in advance
Nov 22 '05 #1
5 6924

"Don" <am****@ix.netcom.com> wrote in message
news:74**********************************@microsof t.com...
hi:

in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now
i'm using vb.net (still getting used to it) and can not figure out how to
hide and show forms. my project presently has a few forms but i can only
the startup form is visible. i can't hide the startup form or show the
other forms. i would like to hide a form when a button is pressed and then
show another.
thanks in advance


To get used to the procedure, do the following:
Create a simple VB Windows project, then add a second form to it.
Place a label on each form so you can identify which form is displayed.
Place a button on each form.

Place the following code in the Click event procedure of the button on Form1
' create instance of Form2
Dim my2 As New Form2
'Hide current form

Me.Hide()

'Display new instance

my2.ShowDialog()

Place the following code in the Click event procedure of the button on Form2
Dim my1 As New Form1

Me.Hide()

my1.ShowDialog()

Hope this helps.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 22 '05 #2

"Don" <am****@ix.netcom.com> wrote in message
news:74**********************************@microsof t.com...
hi:

in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now
i'm using vb.net (still getting used to it) and can not figure out how to
hide and show forms. my project presently has a few forms but i can only
the startup form is visible. i can't hide the startup form or show the
other forms. i would like to hide a form when a button is pressed and then
show another.
thanks in advance


To get used to the procedure, do the following:
Create a simple VB Windows project, then add a second form to it.
Place a label on each form so you can identify which form is displayed.
Place a button on each form.

Place the following code in the Click event procedure of the button on Form1
' create instance of Form2
Dim my2 As New Form2
'Hide current form

Me.Hide()

'Display new instance

my2.ShowDialog()

Place the following code in the Click event procedure of the button on Form2
Dim my1 As New Form1

Me.Hide()

my1.ShowDialog()

Hope this helps.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 22 '05 #3
Hi Don,

There are in VB.net a lot of methods to do that.

Peter did show you a method with a dialogform, it is not real hiding because
the dialogform is everytime new instanced, so the information on it will be
lost. Here a sample with 3 forms which are all the time active, although
form1 is the major form. As a third major form there is the MDI form, where
in a formcontainer can be a lot of child forms.

Most classic VB programmers or the ones comming from C are using a
application.start module, however that is not really necassery in VB.net
because that is build in the form class itself.

I hope this helps?

Cor

\\\form1
Private WithEvents frm3 As New Form3
Private WithEvents frm2 As New Form2
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
If frm2.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm2.inputfield
frm2.Dispose()
End If
End Sub
Private Sub frm3_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm3.VisibleChanged
If frm3.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm3.inputfield
frm3.Dispose()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
frm3.Show()
frm3.TopLevel = True
frm2.Show()
frm2.TopLevel = True
End Sub
///
\\\form2 and 3 the same
Public inputfield As String
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

inputfield = "sometext"
Me.Hide()
End Sub
///

Nov 22 '05 #4
Hi Don,

There are in VB.net a lot of methods to do that.

Peter did show you a method with a dialogform, it is not real hiding because
the dialogform is everytime new instanced, so the information on it will be
lost. Here a sample with 3 forms which are all the time active, although
form1 is the major form. As a third major form there is the MDI form, where
in a formcontainer can be a lot of child forms.

Most classic VB programmers or the ones comming from C are using a
application.start module, however that is not really necassery in VB.net
because that is build in the form class itself.

I hope this helps?

Cor

\\\form1
Private WithEvents frm3 As New Form3
Private WithEvents frm2 As New Form2
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
If frm2.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm2.inputfield
frm2.Dispose()
End If
End Sub
Private Sub frm3_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm3.VisibleChanged
If frm3.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm3.inputfield
frm3.Dispose()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
frm3.Show()
frm3.TopLevel = True
frm2.Show()
frm2.TopLevel = True
End Sub
///
\\\form2 and 3 the same
Public inputfield As String
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

inputfield = "sometext"
Me.Hide()
End Sub
///

Nov 22 '05 #5
well kid the method to implement multiple form is as follows:
add a class to your project named FormLibrary

code as follows

Public Class FormLibrary
Public Shared Form1 As Form
Public Shared Form2 As Form
End Class
then in the form_load event of the different forms add:

FormLibrary.Form1 = Me

for form2 load event

FormLibrary.Form2 = Me

then u may freely access the form properties from any other form as your old habbit using such syntax

FormLibrary.Form1.Hide()
or
FormLibrary.Form2.Show()

You may also do that with a friend class rather than the public class

further dot Net has brought the feature of creating instances of other forms within other forms

code in form1

Dim fm2 as New Form2
fm2.Show()

BUT dont Confuse it with the above methods coz it creates new instance of the form

to know further about the fundas involved email me

check my sites (my childhood creation)

http://3kd.resourcez.com (developed in 2002)
http://humanpsychology.resourcez.com (developed in 2001)
---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
Nov 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by john sutor | last post: by
5 posts views Thread by dancole42 | last post: by
12 posts views Thread by rents | last post: by
3 posts views Thread by tigger | last post: by
2 posts views Thread by =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.