By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,011 Members | 2,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,011 IT Pros & Developers. It's quick & easy.

what is going on in Close()

P: n/a
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But when I
uncomment line 2 it gives error on line 4. I hope to get this behavior even
when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
hi ashish,

Basically Close and dispose are not same.
When u call close on an object, it just closes it.
For example the close call on a SQL connection closes the connection to the
SQL server.
This means that the same object can be and will be used again with a call to
the open connection command.

Dispose in this case disposes off the object itself, so that it cannot be
used again, u need to create a new object to use the object.

The case u have specified is similar to the webform,
U cannot close a form unless it is showing up.....

Hope it helped u get a basic idea about close and dispose,
Regds,
Kannan.V

"Ashish" wrote:
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But when I
uncomment line 2 it gives error on line 4. I hope to get this behavior even
when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish

Nov 16 '05 #2

P: n/a
Hi Kannan,

Actually I know what you told me. Condition is little different then just
calling Dispose() or Close() on the form. Dispose(bool) will be called from
Close() when we do a Show() before calling Close() (stack trace). I was
looking for something deeper in this problem. But thanks for the reply.

"Kannan.V [MCAD.net]" <Ka************@discussions.microsoft.com> wrote in
message news:C6**********************************@microsof t.com...
hi ashish,

Basically Close and dispose are not same.
When u call close on an object, it just closes it.
For example the close call on a SQL connection closes the connection to
the
SQL server.
This means that the same object can be and will be used again with a call
to
the open connection command.

Dispose in this case disposes off the object itself, so that it cannot be
used again, u need to create a new object to use the object.

The case u have specified is similar to the webform,
U cannot close a form unless it is showing up.....

Hope it helped u get a basic idea about close and dispose,
Regds,
Kannan.V

"Ashish" wrote:
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But
when I
uncomment line 2 it gives error on line 4. I hope to get this behavior
even
when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and
then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish

Nov 16 '05 #3

P: n/a
Hi Ashish,

Provided that the window handle has been created, Form.Close sends a
WM_CLOSE message to the window. It is up to the Form's message handling
routine to take it from there. If the window handle has not been created
yet, Form.Close does nothing. The window handle of a form is not created
when the form is created. The window handle does get created when the form
is made visible (there may be other things that would cause the window
handle to be created before the form is made visible).

Regards,
Daniel

"Ashish" <no*****@thisaddress.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But when I uncomment line 2 it gives error on line 4. I hope to get this behavior even when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish

Nov 16 '05 #4

P: n/a
Hi Ashish,

Provided that the window handle has been created, Form.Close sends a
WM_CLOSE message to the window. It is up to the Form's message handling
routine to take it from there. If the window handle has not been created
yet, Form.Close does nothing. The window handle of a form is not created
when the form is created. The window handle does get created when the form
is made visible (there may be other things that would cause the window
handle to be created before the form is made visible).

Regards,
Daniel

"Ashish" <no*****@thisaddress.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But when I uncomment line 2 it gives error on line 4. I hope to get this behavior even when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish

Nov 16 '05 #5

P: n/a
Thanks Daniel, that is what I was looking for.
"Daniel Pratt" <ko******************@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
Hi Ashish,

Provided that the window handle has been created, Form.Close sends a
WM_CLOSE message to the window. It is up to the Form's message handling
routine to take it from there. If the window handle has not been created
yet, Form.Close does nothing. The window handle of a form is not created
when the form is created. The window handle does get created when the form
is made visible (there may be other things that would cause the window
handle to be created before the form is made visible).

Regards,
Daniel

"Ashish" <no*****@thisaddress.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But
when

I
uncomment line 2 it gives error on line 4. I hope to get this behavior

even
when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and
then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish


Nov 16 '05 #6

P: n/a
Thanks Daniel, that is what I was looking for.
"Daniel Pratt" <ko******************@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
Hi Ashish,

Provided that the window handle has been created, Form.Close sends a
WM_CLOSE message to the window. It is up to the Form's message handling
routine to take it from there. If the window handle has not been created
yet, Form.Close does nothing. The window handle of a form is not created
when the form is created. The window handle does get created when the form
is made visible (there may be other things that would cause the window
handle to be created before the form is made visible).

Regards,
Daniel

"Ashish" <no*****@thisaddress.com> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
It might be basics for many but I never gave attention on this before.

Steps:

Add 2 forms (Form1/Form2) in application.
Create a object in Form1 for Form2.

Form2 f2 = new Form2(); //line 1
//f2.Show(); // line 2
f2.Close(); // line 3
f2.Show(); // works just fine // line 4

Give attn on line 2 as it is marked out. In line 4 it shows form. But
when

I
uncomment line 2 it gives error on line 4. I hope to get this behavior

even
when line 2 is commented out.

1- why dispose is not called when I call Close when line 2 is commented?
2- what is happening in Close() when line 2 is commented?
3- why it is working when I create form object, call close on it, and
then
show it?
4- what is happening when I do Show(), Close(), and then Show() ?

In my understanding object is in hidden state after creation. Show only
makes Visible property of form to true. Now I am sure there is something
more to it than just making the form visible.

Thanks a lot,

Ashish


Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.