Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
-Ben LaBore
  • *Experts*
Posted

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.

Posted
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.
-Ben LaBore

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...