Results 1 to 3 of 3

Thread: Question about showing and hiding forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98

    Question about showing and hiding forms

    Okay this might seem kind of a dumb question, but i cant seem to figure it out...

    i have this code in form 1:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    Dim Form2 As New Form2()
    Form2.Show()
    End Sub

    and this code in form 2:

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim form1 As New Form1()
    form1.Hide()
    End Sub


    The problem is that Form2 will show, but it will not hide form1 when it loads, what can i do to fix this, i have tried everything i can think of.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    http://msdn.microsoft.com/library/de...adingtonet.asp

    Required reading.

    What you are doing is creating a new instance of form1 in your form2 code. This isn't affecting the instance that is already created. In order to do form1.hide, you need to have a reference to the already created form1. You can pass in a reference through the constructor of form2, or you can do what that link says to do.

  3. #3
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    I think you can just set the visibility of form1 in the designer to false. If not you can use Me.Hide() or Me.Visible() = False in Form1 load event. The previous post hit the nail on the head.

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