Windows Form within Windows Form

Asked

Viewed 388 times

2

Besides using Splitcontainer, is there any other way to put a Form inside another form, using HTML’s iframe style? Because Splitcontainer I am not able to change the Form data inside it.

1 answer

2


I have been researching, there are many ways to accomplish this, here is a list with possibilities and attempts that 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 like 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 it, good luck.

  • Had already tried, reports error: It is not possible to add top level control to a control.

  • Try to put: Dim frmHost As Control = FormDest.AtacchedControl.

  • Error informs: Cannot add top level control to a control.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.