Results 1 to 8 of 8

Thread: Basic question regarding closing forms.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    19

    Question Basic question regarding closing forms.

    Hi!

    I just recently stared working with VB.net and I've noticed several differences. One of them is confusing me.
    It has to do with the basic handling of forms.

    In my case I have a main form where I have a button which when a user activates should bring up another form and hide the main one.

    The code behind that command button look like this:

    If radCMBO.Checked = True Then
    Dim frmCMOB As New frmCMOB()
    frmCMOB.show()

    ElseIf radCMBB.Checked Then
    Dim frmCMBB As New frmCMBB()
    frmCMBB.show()

    Else
    Dim Front As Integer
    Randomize()
    Front = CInt(Int((2 * Rnd()) + 1))
    If Front = 1 Then
    Dim frmCMOB As New frmCMOB()
    frmCMOB.show()

    Else
    Dim frmCMBB As New frmCMBB()
    frmCMBB.show()
    End If
    End If

    Dim frmCMOB As New frmCMOB() 'this opens one of my new forms
    frmCMOB.show()

    but what should I write in order to close my main form after opening a new without closing the whole app? The user should be able to return to the main form
    frmCMBB and frmCMOB

    Any help would be appreciated..
    Thx.
    -D

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Deloma

    but what should I write in order to close my main form after opening a new without closing the whole app? The user should be able to return to the main form
    Any help would be appreciated..
    Thx.
    -D
    If you closed the mainform (your startup form) then you will close the whole proj . You can hide it though . For other forms , you can use Close() method .

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I mean use this for hiding your main form :

    VB Code:
    1. MainForm.Hide()

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    19
    But how do I show it again from another form?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    19
    frmMain.Hide() generates an error
    It says
    Reference to a non-shared member requires an object reference.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Deloma
    But how do I show it again from another form?
    Best solution for this is to declare all your forms in a module as public like this :
    VB Code:
    1. Public frm1 As New Form1
    2. Public frm2 As New Form2
    3. Public frm3 As New Form3
    Then you can only use different methods of each one as you're doing in VB6 . Something like this :
    VB Code:
    1. frm1.Show 'to show your form back

    You really need to have a look at the link hellswraith posted , it's needed .

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    19
    Thx a lot..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width