Solved

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

Posted on 2013-12-10
17
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

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 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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