hello everyone.
i have a problem with MDI my project there is parent form and child form. in my MDi parent form i had created fix layout panel where i want to show the other child form . but i dot no how to call child form on that fix MDI panel form

Dani AI

Generated

This thread mixes two different hosting models: true MDI child windows (set with a form's MdiParent) and embedding a form inside a Panel. MDI children are confined to the MDI client area and cannot be hosted inside an arbitrary Panel. For a fixed-panel UI (the behavior described by ), either host the form as a non-top-level control or, better, design the content as a UserControl and place that in the panel.

A concise VB.NET pattern to embed a Form inside a Panel (not as an MDI child):

' host a Form inside Panel1 (VB.NET)
Dim f As New Form1()
f.TopLevel = False
f.FormBorderStyle = FormBorderStyle.None
f.Dock = DockStyle.Fill
Panel1.Controls.Clear()
Panel1.Controls.Add(f)
f.Show()
f.BringToFront()

Notes and troubleshooting:

  • TopLevel = False must be set before showing the form. FormBorderStyle = None removes title/borders so the form appears as content. Dock = Fill takes care of sizing instead of manual resize (related to 's resizing point).
  • Clear and Dispose previous controls when swapping views to avoid leaks. Menu merging, focus and keyboard behavior differ from real MDI; if those are needed, use true MDI children instead.
  • The Win32 SetParent API (suggested by ) is a lower-level option but fragile; prefer the managed approach or UserControl for maintainability. The VB6-style techniques from are a different environment and are not interchangeable with WinForms.

Recommended Answers

All 6 Replies

hello everyone.
i have a problem with MDI my project there is parent form and child form. in my MDi parent form i had created fix layout panel where i want to show the other child form . but i dot no how to call child form on that fix MDI panel form

Would you like to show the child form in the fixed panel? I am not sure what exactly you want to do here. I the child needs to fit into the panel, its a matter of form resize codes, else, please send us more details to assist you.

Did you place a picture box on the mdi parent form and hope to show a mdi child form in it??? If so, the SetParent API is what you are looking for. If not, are you sure you set the mdichild propert to true in the intended child form???

Good Luck

in my mdi form i had created two fix panel on form show the child form and another small panel i'm showing the help of that particular form. i want to show only the form on that first fix panel. so i'm using the code like this tell me is this a write code for that

dim frm as new form1
panel1.Controls.Add(frm)
frm.show()

it show the child form
but it does not fit on he panel. what to do now.

As I suspected before, it is all a matter of resizing code. You need to specify the size of the form as well as the position by using the following -

With Form2
.Height = xxxx
.Width = xxxx
.Top = xxxx

etc. Play around with resizing codes, especially if you have users that have different screen resolutions and sizes etc.

If you do not want a user to resize the form, use the panel sizes to fit the form itself. It will not really "fit" into the panel, although that is what the user will see -

With form2
.Width = panel1.Width - 100 'To cover for any borders
.Top = panel1.Top - xxxx 'How ever high you want the form

I hope this helps towards your solution.

huunnn, i tihnk it will work. let me try . but thanks for the help sir

execuse me, i am newer, but I hope it's work. B-cause some time i get code from friends forums. And forgive me if this code it's has yours.
so try this....

Public Sub TB_Zone(frm As Form, Optional vntUseScaleValues As Variant)
    Dim bUseScaleValues As Boolean
    If Not IsMissing(vntUseScaleValues) Then
        bUseScaleValues = vntUseScaleValues
    End If
    With frm
        If bUseScaleValues Then
            TB_ZoneLeft = .ScaleLeft + .Left
            TB_ZoneTop = .ScaleTop + .Top
            TB_ZoneWidth = .ScaleWidth
            TB_ZoneHeight = .ScaleHeight
        Else
            TB_ZoneLeft = .Left
            TB_ZoneTop = .Top
            TB_ZoneWidth = .Width
            TB_ZoneHeight = .Height
        End If
    End With
End Sub

Public Sub TB_CenterForm(frm As Form, Optional vntOffsetLeft As Variant, Optional vntOffsetTop As Variant, Optional vntConsiderTaskbar As Variant)
    Dim lLeft As Long, lTop As Long
    Dim lOffsetLeft As Long
    Dim lOffsetTop  As Long
    Dim bConsiderTaskbar As Boolean
    
    If Not IsMissing(vntOffsetLeft) Then
        lOffsetLeft = vntOffsetLeft
    End If
    If Not IsMissing(vntOffsetTop) Then
        lOffsetTop = vntOffsetTop
    End If
    If Not IsMissing(vntConsiderTaskbar) Then
        bConsiderTaskbar = vntConsiderTaskbar
    End If
    With frm
        If .WindowState = vbNormal Then
            If bConsiderTaskbar Then
            ElseIf TB_ZoneWidth + TB_ZoneHeight > 0 Then
                lLeft = (TB_ZoneLeft + (TB_ZoneWidth \ 2)) - (.Width \ 2) + lOffsetLeft
                lTop = (TB_ZoneTop + (TB_ZoneHeight \ 2)) - (.Height \ 2) + lOffsetTop
                If lLeft + .Width > Screen.Width Then
                    lLeft = Screen.Width - .Width
                ElseIf lLeft < 0 Then
                    lLeft = 0
                End If
                If lTop + .Height > Screen.Height Then
                    lTop = Screen.Height - .Height
                ElseIf lTop < 0 Then
                    lTop = 0
                End If
            Else
                lLeft = ((Screen.Width - .Width) \ 2) + lOffsetLeft
                lTop = (((Screen.Height - .Height) \ 2) + lOffsetTop)
            End If
            If .Left = lLeft And .Top = lTop Then
            Else
                .Move lLeft, lTop
            End If
        End If
    End With
End Sub
Option Explicit
Public TB_ZoneLeft          As Long
Public TB_ZoneTop           As Long
Public TB_ZoneWidth         As Long
Public TB_ZoneHeight        As Long

Private Sub CenterMDIForm()
    Dim lLeft       As Long
    Dim lTop        As Long
    Dim iTemp       As Integer
    Dim sTemp       As String
    Static bOnTop   As Boolean
            TB_Zone Main_Form ' MDI Names
            TB_CenterForm Me, lLeft, lTop
End Sub

<URL SNIPPED>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.