近期有个网友问我这个问题,我就上网搜了下,结果非常失望。有几个在CSDN上发的求助帖。看到最后都没有找到明白的答案。
这里笔者在网上找到了API函数SetParent(),并对网上的错误进行了改动,并给出了简单实例代码。
读者可自行測试:
Public Class Form1 '作者:章鱼哥,QQ:3107073263 群:309816713 '如有疑问或好的建议请联系我。大家一起进步 '声明SetParent函数。这是一个API函数 Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Long Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.IsMdiContainer = True '将Form1设置为父窗口容器 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Form1是父窗口,Form2是子窗口 SetParent(Form2.Handle, Me.Handle) Form2.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click SetParent(Form3.Handle, Me.Handle) Form3.Show() End Sub End Class
截图效果:
时间: 2024-12-25 14:44:05