VB编程....

来源:百度知道 编辑:UC知道 时间:2024/05/10 10:15:21
怎样用VB制作----打开一程序里面有许多个按钮,然后每点一个按钮都能弹出一个新的窗口且里面的内容都不同?

方法很多,下面就说比较常用的二种方法:
方法1:
利用多个Frame控件,以控件的Visible属性决定控件是否可见,显示不同内容,例如:
Private Sub Command1_Click()
Frame1.Visible = True
Frame2.Visible = False
.........
End Sub

Private Sub Command2_Click()
Frame1.Visible = False
Frame2.Visible = True
..........
End Sub

.........

方法2:
利用多窗体显示不同内容,例如:
Private Sub Command1_Click()
Unload Form1-----关闭窗体1
Form2.Show-------打开窗体2
End Sub

Private Sub Command2_Click()
Unload Form2-----关闭窗体2
Form3.Show-------打开窗体3
End Sub

..........

比较:方法1可以用一个窗体,因此如果有共有变量,十分方便,由于只有一个窗体,工程管理比较方便。方法2窗体比较多,但每个窗体的代码比较少,编程相对比较容易。

窗体名.show

新建工程,再Form1上添加一个command1,command1代码

Private Sub Command1_Click()
Dim fm As New Form1
fm.Show
fm.AutoRedraw = True
fm.Print "你要什么不通的内容啊,后面的数字就是随机的->" & Rnd
End Sub

运行就OK了