creating a vb.net project with multiple forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Don said:
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.
 
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
///
 
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)
 
Back
Top