blabore Posted July 29, 2003 Posted July 29, 2003 I have a MDI app which uses a several different child forms (about 10), but at most there is only one instance of each type form. Since loading/showing forms seems to be pretty slow in .NET, it seems like a good idea to sort of cache each form by creating a single instance of each form, then just show the saved instance rather than create a new form each time. Anyone try something like this? Is there any reason to create a new instance of my child forms each time I need one? Any help would be appreciated. Quote -Ben LaBore
*Experts* mutant Posted July 29, 2003 *Experts* Posted July 29, 2003 You could declare all your forms as new only once. What I mean by this is: Dim form1st As Form1 Dim form2nd As Form2 Dim form3rd As Form3 '... 'Then in lets say the load event of the parent initialize them Private Sub Parent_Load(ByVal sender As Object, ByVal e As System.EventArgs) form1st = New Form1() form1st.MdiParent = Me '.... same for all forms Then show them or hide with formname.Show() and formname.Hide(). Or you could store the instances as shared in some class. Quote
blabore Posted July 31, 2003 Author Posted July 31, 2003 This is basically what I do, but I only load the form if it's not loaded (i.e. If myForm is nothing then myForm = New Form1). I'm just wondering if there's any serious disadvantages to keeping each form loaded, especially as far a memory goes. I'm not sure how much memory a form takes, depending on what types of controls are on the form, etc. Quote -Ben LaBore
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.