What does this.Close() do?

G

Guest

Hi,
I'm developing an application in c# for a pocket pc with Windows Mobile 5.0.
I have two forms, let's call them A and B. At a button click in form A I
want to see form B. However, I want to keep form A "alive", to go back to it
later, and collect the data received in form B.
In form B I have a public method which returns a string (the data that I
need). So the event handler for the button click in form A goes like this:

string a;
B b = new B();
b.ShowDialog();
a = b.GetData();

In form B I have some kind of OK button. I want to close and go back to form
A. So that button event just has this line:
this.Close();

What surprises me is that it works good. I thought that after this.Close()
there will be no b, and the call to b.GetData() will fail. But I see that
there is data in a after that (the correct data).
Then I tried this.Dispose() instead of this.Close() , but the results were
the same.
Can anyone please explain to me what's happening here?

Thank you very much
 
K

Kevin Spencer

Set the DialogResult property of the second form. This will cause the form
to hide itself without closing and disposing.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

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