VB 创建窗体问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 08:28:21
Set newform = Form1
....
newform.Show

form1创建多个时,怎么知道创建的这些form1的名字啊?
就是说newform

我要在form2里控制新创建的第N个form1要怎么做?
多谢大家帮忙了哈

If t = 10 Then
'控制第10个窗口的代码
newform.Print "这是第10个窗口"

'模块代码 , 声明一个全局变量: 这样就可以知道相应的窗口了
Public t As Long

'窗体代码:
Private Sub Command1_Click()
Dim newform As New Form1
t = t + 1
newform.Show
newform.Caption = t
If t = 10 Then
'控制第10个窗口的代码
newform.Print "这是第10个窗口"
End If
End Sub

你可以在属性窗口中改他们每一个窗口的名称了。如果真的不行,那么你可以在代码中一个一个来改了。

建议不要用窗体的Caption属性,因为Caption会在程序的其它地方有用。为了区分新建的多个窗体,请使用窗体的Tag属性,如下:
'定义一个全局变量
Dim intForm As Integer

intForm = 1
Set newform = Form1
....
newform.Show
newform.Tag = "NewForm" & intForm
intForm = 2
Set newform = Form1
....
newform.Show
newform.Tag = "NewForm" & intForm

'模块代码 , 声明一个全局变量: 这样就可以知道相应的窗口了
Public t As Long

'窗体代码:
Private Sub Command1_Click()
Dim newform As New Form1
t = t + 1
newf