Help in closing opened form from another form.

ljpv14

Active member
Joined
Nov 28, 2011
Messages
44
Programming Experience
3-5
Guys! I have this form called gamePlay form. This form is showed by my loading form. When the gamePlay form is showed the loading form is closed. At the gameplay form i will be opening another form called congrats form. At congrats form I need to close the gamePlay form. How should I close the gameplay form from the congrats form. I tried creating an instance of the gamePlay form and obviously the gamePlay form won't close since the instance that opened gamePlay was not the one who closed it. I know it's a bit confusing. I hope some could help me.

Here is a code to explain what I meant:

loadingPageForm:
dim gp as gamePlay= new gamePlay()
gp.show()
me.close()

gamePlayForm:
dim cgp as congratsForm = new congratsform()
cgp.show()

congratsform:
'Here at the congrats form, I want to close the current opened gamePlayForm. How should I do it?
 
It sounds likely to me that you have designed this the wrong way. Can you please explain, fully and clearly, what actually happens from the user's perspective with regards to these forms?
 
I didn't fully understood your question regarding my inquiry. Well, I just need the gameplay form to be closed by my congratForm. When the gameplay is showed and I press a button, congrats form will be displayed. Still the gameplay is also displayed. Meaning the congratsForm will be at the top of the gameplay form. Then at the congratsForm, I will be pressing a button. This button should close the gameplay form beneath my congratsForm. That's my problem. :) I'm not sure if I answered your question though.
 
Unless you need more than one instance of a form use the default instance. This is done by simply referring to it by it's name, for example: gamePlay.Show()
The default form instance is available from anywhere in project (from main thread), so in another form you can refer to same instance, f.ex: gamePlay.Close()

If you need multiple concurrent instances of same form you do need to create your own instances. Then you also need to manage the references (held by your variables) to the form instances yourself, and pass them around where you need them. Values/objects are typically passed around by using properties or methods with parameters.
 
Back
Top