1

C# WinForms: When I open my form for the first time, frm1.Hanlde is Ok but when I close my form and open it again,the value for handle is throwing an exception of System.ObjectDisposedException .... what are the things I should consider for debugging and fixing it?

Bohn
  • 26,091
  • 61
  • 167
  • 254

2 Answers2

2

You can't close a form and reopen it.

You can, however, hide, and later on show it again.

But once you close the form, it is disposed, so any attempts at reopening it will give you problems like that, correct.

What are you trying to do?

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • hmm, Ok I will try "Hide" .... I am passing th Handle of this form to a non-.NET OCX contorl ... first time it is ok,,,second time it has the problem I mentioed in the question – Bohn Nov 03 '10 at 17:34
  • 1
    It doesn't matter what you do with the form, once you've closed it, you should stop using it, so don't close it. Either that, or you'll have to construct a new form instance and use that instead, each time. – Lasse V. Karlsen Nov 03 '10 at 17:35
1

Also, keep in mind, when you minimize a window, that window will get a new handle. If your non-.NET ocx control references the old handle, you will crash.

James King
  • 6,233
  • 5
  • 42
  • 63