flynn
02-20-2005, 08: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
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