Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Centering form inside a MDI form
Message
 
 
À
30/03/2001 10:50:21
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00490334
Message ID:
00490446
Vues:
7
>Using VB6.
>
>My app has a MDI form that is opened with WindowState = 2. Another form called menu is opened inside the MDI form.
>
>How can I make the menu form open up centered in the MDI form? I tried placing Me.StartUpPosition = 1 in the menu form's LOAD(). However, when I do this, I get a VB error when running the form. The message starts with:
> Function or interface marked as restricted
>
>How can I get any form to startup centered in a MDI form?
>
>Thanks,
>
>Jerryt

Here are a few things I use with MDI forms. HTH.
Public Sub Center(frm As Form, Optional frmMDI As Variant)
Dim ret
    'Syntax: Center Form1, [MDIForm1]
    ret = IsMissing(frmMDI)

    If ret = False Then
        frm.Top = (frmMDI.ScaleHeight - frm.Height) / 2
        frm.Left = (frmMDI.ScaleWidth - frm.Width) / 2
    Else
        frm.Top = (Screen.Height - frm.Height) / 2
        frm.Left = (Screen.Width - frm.Width) / 2
    End If
End Sub

Public Sub CenterChild(Parent As Form, Child As Form)
    'Syntax: CenterChild MDIForm1, Form1
    Dim iTop As Integer
    Dim iLeft As Integer
    If Parent.WindowState <> 0 Then Exit Sub
    iTop = ((Parent.Height - Child.Height) \ 2)
    iLeft = ((Parent.Width - Child.Width) \ 2)
    Child.Move iLeft, iTop ' (This is more efficient than setting Top and Left properties)
End Sub
 
Public Sub UnloadAllChildren()
    Dim vForm As Variant
    For Each vForm In Forms
        If Not TypeOf vForm Is MDIForm Then
            If vForm.MDIChild Then
                Unload vForm
            End If
        End If
    Next  'vFrom
End Sub
 
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform