Solved

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

Posted on 2013-12-10
17
180 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
17 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 85

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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now