Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-16
2
Medium Priority
?
217 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
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

782 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