Solved

closing winform

Posted on 2009-03-30
6
409 Views
Last Modified: 2013-12-17
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 };
formBrowser.Show();

Open in new window

0
Comment
Question by:amillyard
6 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 24018064
Have you put in a breakpoint to see if formBrowser is null?  
0
 

Author Comment

by:amillyard
ID: 24018331
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
0
 
LVL 9

Expert Comment

by:VikramMullick
ID: 24018551
try
formBrowser.Showdialog(this)
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 200 total points
ID: 24018561
you should check for null or IsDisposed
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 300 total points
ID: 24018587
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();
 
            f.Show();
        }
 
        Form5 f = null;

Open in new window

0
 

Author Closing Comment

by:amillyard
ID: 31564285
carl_tawn: & emoreau:  works great now :-)   many thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question