将MdiForm内的Form移出MdiForm

事实上,这是设定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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值