Show and close forms

magpies18

Member
Joined
Oct 3, 2008
Messages
12
Programming Experience
Beginner
well i encountered another problem regarding the use of 2 forms, this was the problem...i had 2 forms one the main menu and the other a second form with details, so when i clicked on the main menu form to show the other form, the other form does show up but the main menu is still there.And in the second form when i press the back command, the second form still stays there but a new main menu form shows up....here was the coding for the main menu form
VB.NET:
dim frl as new form1
dim frm as new form2
frm.show()
frl.close()
the form1 is the main menu form and form 2 is the second form...so wats wrong why doesnt my other form close?
 
Try this...

VB.NET:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fr2 As New Form2
        Me.Hide()
        Fr2.Show()
    End Sub
End Class

What I did was that I had 2 Forms...(Form1 is the main form... Form 2 is the one which loads)

I added a button(button1) control on to form1.....When a user Clicks that button(you can see in the click events) Form1(or Me as I have referred to it in the code) HIDES and Form2 shows....

I don't think that closing the form1 would be a good idea since that would just end the application because we have form1 as the main form and I don't think we can let that close....


Well That was all I could Help... I am not like a pro at VB like other people here =/...But that's the most I could Help =D


EDIT: Correct me if I am wrong =D...also to answer your question I really don't know why your form won't close...But I don't think it should close because then since your form1 is the MAIN form it shouldn't close....I guess...I am not sure though....Try out Different Things your Self =D

EDIT #2: Its Fun to play around with VB...I attached a fun demo file...hehe...
 

Attachments

  • Demo.zip
    71.6 KB · Views: 25
Last edited:
Back
Top