Windows Form within Windows Form

2

In addition to using SplitContainer, is there any other way to place a Form inside another form, using HTML-style iframe? For the SplitContainer I am not able to change the data of the Form inside it.

    
asked by anonymous 20.10.2015 / 00:32

1 answer

2

I've been researching, there are many ways to accomplish this, here is a list of possibilities and attempts you can make:

Example I

Place this method in the base class (where you will add the controls):

Public Function PerformControls(ByVal Expression As Form) As Control
  Dim tmp As New Control With
     {
         .Size = Expression.Size,
         .Location = Expression.Location,
         .Cursor = Expression.Cursor,
         .Font = Expression.Font,
         .BackColor = Expression.BackColor,
         .ForeColor = Expression.ForeColor
     }
  For Each item As Object In Expression.Controls
     tmp.Controls.Add(item)
  Next
  Return tmp
End Function

To use, try this:

Private Sub Form_Load(sender As [Object], e As EventArgs) Handles MyBase.Load
     Me.Controls.Add(PerformControls(New FormDest)) 'FormDest é o nome da classe destino
End Sub
Example II

Add this function:

 Public Shared Sub ShowFormInControl(ByRef ctl As Control, ByRef frm As Form)
     If ctl IsNot Nothing AndAlso frm IsNot Nothing Then
         frm.TopLevel = False
         frm.FormBorderStyle = FormBorderStyle.None
         frm.Dock = DockStyle.Fill
         frm.Visible = True
         ctl.Controls.Add(frm)
    End If
 End Sub

To use:

Private Sub Form_Load(sender As [Object], e As EventArgs) Handles MyBase.Load
     ShowFormInControl(Me, New frmDest)
End Sub

Try to do this, good luck.

    
21.10.2015 / 22:08