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.
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.
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:
Private frmParent As Form1 = Me.Owner
Then, when closing the child form, run this line of code
VB Code:
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
frmParent.Show
End Sub
Last edited by CyberHawke; Jun 28th, 2004 at 01:13 PM.