Solved

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

Posted on 2013-12-10
17
174 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

19 Experts available now in Live!

Get 1:1 Help Now