Interesting, I did not know that.
Printable View
Interesting, I did not know that.
Put a picturebox on form 1, then in the load event of form1, put this code :
Just remember. You'll have to Unload all forms properly, ie:Code:Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
Dim frmForm As Form2
Set frmForm = New Form2
SetParent frmForm.hwnd, Picture1.hwnd
frmForm.Show
End Sub
Else you will find that form 2 will still be in memoryCode:Private Sub Form_Unload(Cancel As Integer)
Static bUnloading As Boolean
Dim intI As Integer
If bUnloading Then Exit Sub
bUnloading = True
For intI = Forms.Count - 1 To 0 Step -1
Unload Forms(intI)
Next intI
End Sub
I hope this helps :)
This will show Form2 inside the picturebox on Form1
That's a really good one, Hannes.
I played with this and found you could also use Form2 directly without creating a new instance of it.
and we could also omit the picturebox and cling Form2 directly to Form1:Code:SetParent Form2.hWnd, Picture1.hWnd
And a last hint for the op to implement this:Code:SetParent Form2.hwnd, Form1.hwnd
After the Form2.Show (or frmForm.Show) do a Form2.Move 0, 0 or give it a distinct position within the new parent.
When I tried this first I wondered why the Form2 did not show, when I came upon the fact that the initial .Top and .Left of the form put it out of the visible range.
@DataMiser: In the SetWindowPos description it says
· parameter hWndInsertAfter
Identifies the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values:
HWND_BOTTOM, HWND_NOTOPMOST, HWND_TOP, HWND_TOPMOST
which are -4, -3, -2 and -1 respectively