Opening and Closing Forms

H

HardySpicer

I have my main form and say a second form Form2.vb

I define

dim f2 as new Form2 (or whatever the namespace is)

then have a button on Form 1 which has

f2.open()

and a button on Form2

me.close() (or me.hide() )

trouble us that if somebody exits by hitting the cross at the top
right of the window (ie the standard window button for terminating a
form) then I get an error when I try and re-open the form. What is the
solution to this one?

thanks

H.
 
C

Cor Ligthert[MVP]

H,

You can say e.cancel = true in the close event or much nicer disable the X
in the box.

Cor
 
A

Armin Zingler

HardySpicer said:
I have my main form and say a second form Form2.vb

I define

dim f2 as new Form2 (or whatever the namespace is)

then have a button on Form 1 which has

f2.open()

and a button on Form2

me.close() (or me.hide() )

trouble us that if somebody exits by hitting the cross at the top
right of the window (ie the standard window button for terminating a
form) then I get an error when I try and re-open the form. What is the
solution to this one?

A modeless Form is disposed after it has been closed. You have to create a
new instance. Or, as Cor already said, handle the FormClosing event and only
hide Form2 instead (while setting e.cancel = true). But be aware to not do
it in any case because you would never be able to close it again. So, give
Form2 a chance to be close under some
circumstances.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top