Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-10
17
Medium Priority
?
187 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

876 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