VB怎样动态创建一个代码相同的窗体
例如我有一个窗体Form1,里面我已经设定好控件、编辑好代码。然后在程序运行时,我怎样通过代码动态创建一个与Form1内容(已有控件、代码)完全相同的窗口,然后.show...
例如我有一个窗体Form1,里面我已经设定好控件、编辑好代码。
然后在程序运行时,我怎样通过代码动态创建一个与Form1内容(已有控件、代码)完全相同的窗口,然后.show显示出来? 展开
然后在程序运行时,我怎样通过代码动态创建一个与Form1内容(已有控件、代码)完全相同的窗口,然后.show显示出来? 展开
2个回答
展开全部
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Dim NewForm(0 To 100) As New Form1
Dim N As Long
Private Sub ExitMe_Click()
UnloadAll_Click
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnloadAll_Click
End Sub
Private Sub MakeNew_Click() '新建一个窗体
Load NewForm(N)
SetParent NewForm(N).hWnd, Me.hWnd
NewForm(N).Show
NewForm(N).Caption = "子窗体 - " & N
NewForm(N).Tag = N
N = N + 1
Form1.SetFocus
End Sub
Private Sub SearchOne_Click() '查找某个窗体
Dim RES As String
RES = InputBox("请输入要查找窗体的索引号:(0 To 100)", "请输入:")
If RES <> "" And NewForm(CLng(RES)).Visible = True Then NewForm(CLng(RES)).SetFocus
End Sub
Private Sub UnloadAll_Click() '关闭所有子窗体
For Each TheForm In NewForm()
If TheForm Is Nothing Then Exit For
Unload TheForm
Next
N = 0
End Sub
Dim NewForm(0 To 100) As New Form1
Dim N As Long
Private Sub ExitMe_Click()
UnloadAll_Click
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnloadAll_Click
End Sub
Private Sub MakeNew_Click() '新建一个窗体
Load NewForm(N)
SetParent NewForm(N).hWnd, Me.hWnd
NewForm(N).Show
NewForm(N).Caption = "子窗体 - " & N
NewForm(N).Tag = N
N = N + 1
Form1.SetFocus
End Sub
Private Sub SearchOne_Click() '查找某个窗体
Dim RES As String
RES = InputBox("请输入要查找窗体的索引号:(0 To 100)", "请输入:")
If RES <> "" And NewForm(CLng(RES)).Visible = True Then NewForm(CLng(RES)).SetFocus
End Sub
Private Sub UnloadAll_Click() '关闭所有子窗体
For Each TheForm In NewForm()
If TheForm Is Nothing Then Exit For
Unload TheForm
Next
N = 0
End Sub
追问
为什么一运行,整个程序包括IDE瞬间退出?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询