Place 1 form on another form

flynn
02-20-2005, 09:21 PM
I am trying to use the following code to place a form (call it 'frmSubForm') on another form (call it 'MainForm'). The code works in that the subform is placed on the main form but I can't get the subform to position correctly. I would like it to be positioned at the upper left corner of the main form.

Does anyone have examples of what I am trying to do? Or any reason why the sub form won't position correctly?


Option Explicit

Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long

Private lngSubFormHwnd As Long


Private Sub Form_Load()
frmSubForm.Left = MainForm.Left
frmSubForm.Top = MainForm.Top

lngSubFormHwnd = SetParent(frmSubForm.hWnd, MainForm.hWnd)
frmSubForm.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
Unload frmSubForm
End Sub

MikeJ
02-20-2005, 09:35 PM
Why don't you use MDI forms? Anyways, to fix that problem, just set frmSubForm's Left and Top properties to 0, instead of MainForm's left and right properties. It's all relative; you don't need to make frmSubForm's properties any different than if you weren't making it inside MainForm.

flynn
02-21-2005, 12:40 PM
Thanks, MikeJ

The reason I am doing it this way is that this application MUST be setup how I have (had) it, but I ran into the maximum control limit per form. So, I broke half of the controls off into another form and now I am putting that form (border set to none) back onto the main form so that it all looks and acts like 1 form (for the most part). Not the best way to create an app but I am stuck with the requirements given to me.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum