Re: MDIForm Parent/Child forms BEST Practice

From: EricJ (ericReMoVe_at_ThiSbitconsult.be.RE)
Date: 04/22/04


Date: Thu, 22 Apr 2004 10:28:05 +0200

I don't know if w i do is the best way of doing things but it works. i'll
try to put it under your questions.

"Edwinah63" <edwinah@customercare.com.au> wrote in message
news:d714e824.0404211752.c0bb836@posting.google.com...
> Hi everyone,
>
> could someone give me some thoughts on the best way to manage mdi
> parent and child forms?
>

First i always create a public var of my main form (mdi parent) for easy
access (yust declare it in a module and i the parent.load set the var to me)

> in vb6 i could scroll through the forms collection and determine which
> forms were open/closed and their current state. now i can't.
>

something like this?
  For Each f As Form In fmMain.MdiChildren
   If f.Visible Then

   End If
  Next

> before i didn't have to declare numerous named instances each time i
> loaded or unloaded a form.
>
the named instance is declared locally so once you are out of this sub it is
gone
        Dim manPSNT As New frmManPSNType
        manPSNT.MdiParent = Me
        manPSNT.Show()

> if i open a child form from another child form and try to assign
> mdimain as the mdiparent it doesn't permit it, if i say f1.mdiparent =
> me.mdiparent i get memory problems (as have others judging from the
> groups).
>

I use the public instance of my main form to do this. But i have don it w
the me.MdiParent should work. (unless you are doing strange things in the
client forms, try loading them non mdi first)

> all my current forms are declared public shared in mdiMain, but should
> these be in a user made forms collection owned by a global module
> (cMain)?

you that would be more organized but generally you don't need them all

> if i am finished with a child form, i want to unload it, not hide it,
> but if i close a form in vb.net it extinguishes the instance.
>
sounds right you will have to assign a new instance of the form to the var,
it all depends on w you want to do at that givven time.

> when the mdi parent closes, i would like the app to terminate.
>
try this

 Private Sub frmMain_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
  Application.Exit()
 End Sub

> should i be setting mdi children to nothing or disposing them?
>
.NET will do that for you

> basically, what can/should i do to get the same mdi parent/child
> management present in vb6 while still preserving the smallest
> footprint possible in memory?

if you want less mem don't declare all your forms as globals, .NET handles
it rather good the standard way.

>
> all comments/code greatly appreciated. i am probably not the only
> programmer to ponder this question.
>
> regards
>
> Edwinah63

There are probably bether ways to do some things, comments are welcome.
Hope it helps a bit

Eric



Relevant Pages

  • Re: Where to DIM
    ... So if the var is only used in one procedure, declare (Dim) at the top of ... If the var is used by more than one procedure, declare it at the module ... Sub Proc1() ...
    (microsoft.public.access.modulesdaovba)
  • Re: variable scope in a webform only
    ... Just declare the variable inside the page class, ... I d like to see that variable from all the Sub of that webform ... I've declared that var as Public shared, but I realize now that that ...
    (microsoft.public.dotnet.framework.aspnet)
  • sundial program
    ... It designs sundials. ... DECLARE SUB KeyPause ... PRINT "Should screens be saved to disk, ...
    (comp.lang.basic.misc)
  • Re: Error Handleling
    ... Dim StrSkillList As String ... Dim var, var2, var3 ... For var2 = 0 To UBound ... Private Sub cmdOK_Click ...
    (microsoft.public.word.vba.general)
  • Re: Declarations variables, Dim, some guidance please
    ... I have a sub called zRM_Values which is called at the begining of larger ... it's kinda a good thing for me that other macros ... > By preference, I try to declare only ... > You didn't get a duplicate Dim error because one variable was declared ...
    (microsoft.public.excel.programming)