Form questions

fkheng

Well-known member
Joined
May 8, 2003
Messages
155
Location
Malaysia
Er....wat does .repaint do for a form? is it like a refresh?

Also, I want to call form B from form A which, i want to close after calling the form B. My code in form A is like :

formB.show()
me.close()

however, after i do this, the whole program terminates

if i do

formB.show()
me.hide()

with this, formA is still active...
someone did suggest to set the formA to nothing, how do I do that?

also, is there a better way around this?
 
yeah
i can do this, but when i close form B, form a will still be active since it is actually hiding there, is there anyway of fully closing it at the same time doing formB.show()?

im doing htis when i click some button...
 
If the FormA is the one you start with you cant fully close it as it was the form that started the message loop for the application and if you close it, app will shut down. You have to hide it.
 
Actually fkheng, you are right. I have stumbled upon this little doozy as well. When you hide "FORM A" and show "FORM B", there is no way to get back to the original "FORM A". You have to create a new instance of "B", and hide "A".

Dim newFormA as New FormA
newFormA.show()
me.hide

Heres where it get tricky, the only way to close the whole app using me.close is if you do it on the first created form. So if you now want to go back to formA from FormB, just Me.Close FormB and create a new instance of FormA. If at any time you want to shut down the whole program, use "End."

At all times "except at first" you will have 2 forms running--the hidden FORMA and the other currently visible file.
 
You can get back to the original one, you would have to pass in the instance of the original one to the second one through constructor and then just do variablewithinstance.Show() in the second one.
 
Go to Sub New in your second form:
And modify it like this:
Code:
Dim form1nd as Form1 variable to hold the instance outside of
constructor
Public Sub New(ByVal firstform as Form1) accept an instance
MyBase.New()
InitializeComponenets()
form1nd = firstform get the instance to a vriable you can use
outside of constructor
end sub
From there you will just have to use the form1nd variable to access the instance of that form.
And when you initialize your second form in first one do this:
Code:
Dim Formtwo as new Form2(Me)
This will pass in your forms instance.
 
i see, cool, i did not know that we could just add watever parameters we like to form our own version of a constructor!
 
Back
Top