Results 1 to 5 of 5

Thread: Hiding a form while another form is open

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3

    Hiding a form while another form is open

    I'm fairly new to Visual Basic and have been trying to figure out how to do this.

    What I want to do is when the user clicks a button on one window to pop-up another window, that first window hides as the new window pops up. Then, when the user is done with the new window, when it closes, the first window pops-back up again.

    I know of the functions Hide, Show, Visible, etc

    My problem is when I write my button-click event, the first window continues to execute. So even though the old window hid, it'll still continue down the execution process and become visible again despite what the new window is doing.

    A hide in a while loop just merely hangs the application.

    There are only 2 ways I can think of doing this, one - use threads so I can pause the first-window execution while the new window is running...or

    Dump the first window all together and create a new instance of the first window in the new window -- refilling all the first window's data when I exit the new window (not going to be fun)


    Is there some VB trick I'm missing that can make this easier to do?


    Also, a second question. How can I make the second window have the same location on the screen that the first window had? That way the user isn't presented with window pop-ups that are in random spots on their screen.

  2. #2
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Hi,

    See if this sample project can teach you something new.

    Cheers,
    McoreD
    Attached Files Attached Files

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3
    Thanks, but that example still doesn't solve my problem.

    In that example, Form2 creates a new instance of Form1, so the original Form1 still stays hidden while Form2 creates and shows a brand new Form1

    For instance, when I type text in Form1 -- Then "hide and show form2", form 2 opens. When I hit "hide and show form1", Form2 shows a brand new instance of Form1 and thus the text I entered earlier doesn't show.

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    When you have a form create a new instance of another form, upon loading the new instance, create an object reference to the owner form in the child form like this:

    VB Code:
    1. Private frmParent As Form1 = Me.Owner

    Then, when closing the child form, run this line of code

    VB Code:
    1. Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.     frmParent.Show
    3. End Sub
    Last edited by CyberHawke; Jun 28th, 2004 at 01:13 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3
    ^^ That worked Thanks a bunch

    For reference to other newbies:

    In form1, I made form1 the owner of form2 by:

    Me.AddOwnedForm(Form2)

    Then I hid Form1, then showed Form2

    In Form2, on close, I used the above method to create a reference, then just did show on the newly created form1

    Thanks again


    I also managed to figure out my second problem:

    Form2.Location = New System.Drawing.Point(Me.Location.X, Me.Location.Y)

    Last edited by tenguman; Jun 28th, 2004 at 01:55 PM.

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