[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to delete a MDIParent if it is called  over and over again

Posted on 2013-12-10
17
Medium Priority
?
189 Views
Last Modified: 2014-01-07
I am having issues with how a form is loaded and is called as it is set to the me.MdiParent then another form is loaded over top of the MdiParent. How can I delete the MdiParent once that second form is loaded.
0
Comment
Question by:cmdolcet
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 39709823
How you do this will depend on how the second form is loaded in the first place.

Can you post the code that loads the two forms?
0
 

Author Comment

by:cmdolcet
ID: 39717450
Ok, the code is attached. It will load frmMain which is a set to a IsMdicontainer. It loads the form and then call the another form (which I call form 1, you will see it on the code as frmOpenRuncreatePartfile) .This is the form that keep getting re created and cause issues that i am trying to avoid.
After the form 1 open I have a DataReceive interrupt, which will be trigger if an open command is sent and then a timer is triggered  it will call the second form frmRuntime. This form 2  opens up over the top of  the first form in the background which is good. The problem is once another open command is picked up by the form 2 trmPartfileLoaded sub if should close down all the forms except the frmMain (which is set to the IsMdiContainer) this shoudl stay open and then open up a new frmOpenRunCreatePartfile).

The problem is that multiple frmOpenRunCreatePArtfiels open in behind my form 2( which I dont call they just stay open).


I hope this helps.
Example-Code.txt
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39724309
I am confused by the word "Delete".  Do you mean "Hide" instead?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:cmdolcet
ID: 39724355
the problem is that the form keeps getting redrawn over and over and it just keep doing it, which if its over 2000 times slows down the program and causes issues.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39724370
You need to get a trace of the program execution.  What version of Visual Studio.NET do you have?  The Ultimate edition comes with Intellitrace, which can give you a list of what occurs during program execution.
0
 

Author Comment

by:cmdolcet
ID: 39724777
I am running VS 2005
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39724848
Can you describe what this application does?  

You should be able to add a breakpoint in the constructor for the MDI parent form, so that you can see when new instances are being created.  Then, look in the call stack, to see where each new instance is created from.
0
 

Author Comment

by:cmdolcet
ID: 39724862
I take a screen shot of what it does.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39724990
Every time your Timer() "trmPartfileLoaded" fires, an additional instance of that form is being created.  Are you sure this isn't causing the problem?  Your timer is probably firing more often than you think it is...
0
 

Author Comment

by:cmdolcet
ID: 39725022
Its really anyone guess. When I put a breakpoint on there It doesn;t seem like its redrawing.
0
 

Author Comment

by:cmdolcet
ID: 39725195
OK the screen I am talking about is in behind Runtime screen is the two Welcome to Universal Gage Interface screens, There should only ever be 1 of these screens open at once. Something is eiter not closing out, or opening it twice.
Screen-shot.png
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39725230
According to idle_mind, a new instance of the form is created every time the timer is fired:

 Dim runFile As frmNewRuntime = New frmNewRuntime
 runFile.MdiParent = Me
 runFile.Show()

Open in new window

0
 

Author Comment

by:cmdolcet
ID: 39726553
Yes this is correct however It only works if I call the instance again otherwise it will fail.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39726865
There is too much code there to try to help, without any explanation of what is happening.  The only thing that we can do is to help you find the information that you need to help yourself.  That requires tracing, debugging, logging, or whatever it takes to gather information about what method is creating more instances of the child form than you need.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 39732115
"There should only ever be 1 of these screens open at once"

Declare the variable for this form at Class level (in the MdiParent) so you can work with it without creating a new instance each time.
Public Class frmMain

    Private runFile As frmNewRuntime = Nothing

    ' ... other code ...

End Class

Open in new window


Then, whenever you need that form, do something like:
    If IsNothing(runFile) OrElse runFile.IsDisposed Then
        runFile = New frmNewRuntime
        runFile.MdiParent = Me
        runFile.Show()
    End If

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

590 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