Avatar of cmdolcet
cmdolcet
Flag for United States of America asked on

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

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.
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Mike Tomlinson

8/22/2022 - Mon
ChloesDad

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

ASKER
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
Bob Learned

I am confused by the word "Delete".  Do you mean "Hide" instead?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
cmdolcet

ASKER
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.
Bob Learned

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

ASKER
I am running VS 2005
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bob Learned

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

ASKER
I take a screen shot of what it does.
Mike Tomlinson

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...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
cmdolcet

ASKER
Its really anyone guess. When I put a breakpoint on there It doesn;t seem like its redrawing.
cmdolcet

ASKER
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
Bob Learned

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
cmdolcet

ASKER
Yes this is correct however It only works if I call the instance again otherwise it will fail.
Bob Learned

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.
ASKER CERTIFIED SOLUTION
Mike Tomlinson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.