• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

closing winform

Can open a 2nd WinForm via the 1st main WinForm.

Created an association (ownership) between the 1st and newly opened 2nd WinForm

The scripting also checks to see if the WinForm has been opened already ... this works (appears too).

Issue is:  when closing the 2nd WinForm and then wanting to open it again I call the opening WinForm script again -- but I cannot reopen the WinForm (once closed) -- I suspect it has something to with the formBrowser  null  status.

How do I reset this parameter or get working correctly?
// WinForm #1
FormBrowser formBrowser;
if (formBrowser != null) return;
formBrowser = new FormBrowser { Owner = this };

Open in new window

2 Solutions
Have you put in a breakpoint to see if formBrowser is null?  
amillyardAuthor Commented:
angus_young_acdc:  checking the breakpoint ... null the 1st time called.  the 2nd onwards is not displayed as null, but is soft of empty !   when disposing the WinForm, it is not resetting back to null status
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Éric MoreauSenior .Net ConsultantCommented:
you should check for null or IsDisposed
Carl TawnSystems and Integration DeveloperCommented:
It won't. Closing the form will not nullify the variable that was pointing to it.

You are best to check for null, or if the form is Disposed:
        private void button1_Click(object sender, EventArgs e)
            if (f == null || f.IsDisposed)
                f = new Form5();
        Form5 f = null;

Open in new window

amillyardAuthor Commented:
carl_tawn: & emoreau:  works great now :-)   many thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now