最近有个网友问我这个问题,我就上网搜了下,结果很失望,有几个在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-15 01:43:16