Solved

Cant use a VERY easy and basic form feature in VB.Net, coming from VB6

Posted on 2004-10-16
2
208 Views
Last Modified: 2010-04-23
Well, this is an easy question I suppose, but I couldn't figure out how to use this in VB.NET using MSDN.
Suppose I have 2 forms, each has a button.
I want it so that if I press the button on form1 it will disappear and form2 appear, the same with form2.
When I press the button on form2 it should disappear and form1 appear.

Now, declaring a form2 type variable in form1 and assigning it to in the initialization in the designer code region:
Frm2 = New Form2(Me)

Then a function in form2 would:
Public Sub New(ByVal host As System.Windows.Forms.Form)
        Frm1 = host
End Sub

When Frm1 is type Form1.

Then I used the following fuctions to make the forms appear and disappear, in form1:
Frm2.Show()
Me.Hide()

In form2:
Frm1.Show()
Me.Hide()

Well It opened Form2  as needed and form1 disappeared, but when i pressed the button on Form2 it would just show a blank form, a real NEW form.

How do I make it right?
Thanks
0
Comment
Question by:NightBlader
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 12328043
There are several ways to go about it.  If you only have two forms then you can use the approach below.  If you push the button on either form then the forms will swap.  If you push the close button [X] on either form the application will end.

~IM

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents f2 As Form2 = New Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()
        f2.Show()
    End Sub

    Private Sub f2_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles f2.VisibleChanged
        If Not f2.Visible Then
            Me.Show()
        End If
    End Sub

    Private Sub f2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles f2.Closed
        Me.Close()
    End Sub
End Class

Public Class Form2
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()
    End Sub
End Class
0
 

Author Comment

by:NightBlader
ID: 12328178
Yep,
Thanks, it works.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question