事实上,这是设定Container的问题,但Form中没有Container的属性,所以使用SetParent来做,不过,这和VB中Parent的属性是不太相同的,VB的Parent指的是这个控制项(或window)是哪一个Window的子Window(Parent Window destory时Child Window也会Destory)而VB的Container指的是子控制项会随着Container所指的Window来定位置,例如:command1放在Frame中,则Command Button的Parent是Form,而Container是Frame,即Command Button随Frame移动,但Form结束时也随之Destory。
而SetParent是指Container的转换,而非VB中Parent属性的转换。
'需一个MdiForm ,一个Form1并事先设其MdiChild = True, 另有2个Command Button
' below is in Form1
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private OldContainer As Long
Private Sub Command1_Click()
OldContainer = SetParent(Me.hWnd, 0)
End Sub
Private Sub Command2_Click()
Call SetParent(Me.hWnd, OldContainer)
Me.Move 0, 0
End Sub
Private Sub Form_Load()
Command1.Caption = "移出"
Command2.Caption = "移入"
End Sub
' below is in MDIForm1
Private Sub MDIForm_Load()
Form1.Show
End Sub
而SetParent是指Container的转换,而非VB中Parent属性的转换。
'需一个MdiForm ,一个Form1并事先设其MdiChild = True, 另有2个Command Button
' below is in Form1
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private OldContainer As Long
Private Sub Command1_Click()
OldContainer = SetParent(Me.hWnd, 0)
End Sub
Private Sub Command2_Click()
Call SetParent(Me.hWnd, OldContainer)
Me.Move 0, 0
End Sub
Private Sub Form_Load()
Command1.Caption = "移出"
Command2.Caption = "移入"
End Sub
' below is in MDIForm1
Private Sub MDIForm_Load()
Form1.Show
End Sub