第 14章 多窗体程序设计
人民邮电出版社
21世纪高等学校计算机基础教育系列教材建立多窗体应用程序
多窗体程序设计相关的语句:
Load 语句
Unload 语句
Show语句
Hide语句多窗体的执行与应用
详细举例完成
可调用程序代码 ( form1)
Private Sub Command1_Click()
Form2.Show
Me.Hide
End Sub
Private Sub Command2_Click()
Form3.Show
Me.Hide
End Sub
Private Sub Command3_Click()
Form4.Show
Me.Hide
End Sub
Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
Static i As Integer
i = i + 1
If i Mod 10 = 0 Then
Print Chr$(KeyCode); "---"; Hex$(KeyCode); " ";
Print,Print
ElseIf KeyCode = 13 Then
i = 0
Print,Print,Print
Else
Print Chr$(KeyCode); "---"; Hex$(KeyCode); " ";
End If
End Sub
程序代码( form2)
Dim paintnow As Boolean
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_DblClick()
Cls
End Sub
Private Sub Form_Load()
DrawWidth = 4
ForeColor = RGB(255,0,0)
End Sub
Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As
Single)
paintnow = True
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As
Single)
If paintnow Then
PSet (X,Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As Single,Y As
Single)
paintnow = False
End Sub
Dim trace As Boolean
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X
As Single,Y As Single)
r = Rnd * 800
If r < 200 Then r = 200
trace = True
Circle (X,Y),r
End Sub
Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As
Single,Y As Single)
trace = False
End Sub
程序代码( form3)
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_Click()
MouseIcon = LoadPicture("f:\djks\ppt\on.ico")
End Sub
Private Sub Picture1_Click()
picture1.Picture = LoadPicture("f:\djks\ppt\hn.jpg")
End Sub
程序代码( form4)
多窗体程序的保存与执行
设置工程的启动窗体,如果没有启动窗体或过程的话,工程将无法运行,
执行方法如下:
工程?工程 1属性,打开如下窗口,在其中选择启动对象。
保存多窗体:在新建工程中直接保存即可(要同时保存 工程 和 窗体 )
装入工程,打开工程即可,无须每个窗体打开一次。
工程的扩展名 vbp
窗体的扩展名 frm
注意:可以从最新和现存中选择,以最快速度地找到你的工程文件
Visual basic 工程结构
包括标准模块、窗体模块和 sub main 过程
如:
下列选项中,不属于 vb主要模块的是:
A 标准模块 C 工程模块
B 窗体模块 D 类模块
答案是:
完整的应用程序的组成:结构图工程组
VBG
工程 vbp
工程 vbp
工程 vbp…
标准模块 bas
窗体模块 frm
类模块 cls
全局变量声明模块层声明
Sub main过程通用过程窗体层声明通用过程事件过程闲置循环与 doevents语句
闲置:无事件在触发时 忙碌:正在执行某事件触发程序
闲置循环,idle loop:在空闲时用一个循环来执行其他操作,就是在闲置情况执行的循环。闲置循环时,cpu全部占用,要夺回 cpu控制权,用
doevents来实现。 Doevens 即可作为语句,也可作为函数。例如:
Private Sub Command1_Click()
FontSize = 12
Print "执行按钮 1的单击事件过程 "
For i = 1 To 10000
x = x * 2
Next i
End Sub
Private Sub Command3_Click()
End
End Sub
Sub main()
Form1.Show
Do While DoEvents()
If Form1.Command2.Left
<= Form1.Width Then
Form1.Command2.Left =
Form1.Command2.Left + 1
Beep
Else
Form1.Command2.Left =
Form1.Left
End If
Loop
End Sub
人民邮电出版社
21世纪高等学校计算机基础教育系列教材建立多窗体应用程序
多窗体程序设计相关的语句:
Load 语句
Unload 语句
Show语句
Hide语句多窗体的执行与应用
详细举例完成
可调用程序代码 ( form1)
Private Sub Command1_Click()
Form2.Show
Me.Hide
End Sub
Private Sub Command2_Click()
Form3.Show
Me.Hide
End Sub
Private Sub Command3_Click()
Form4.Show
Me.Hide
End Sub
Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
Static i As Integer
i = i + 1
If i Mod 10 = 0 Then
Print Chr$(KeyCode); "---"; Hex$(KeyCode); " ";
Print,Print
ElseIf KeyCode = 13 Then
i = 0
Print,Print,Print
Else
Print Chr$(KeyCode); "---"; Hex$(KeyCode); " ";
End If
End Sub
程序代码( form2)
Dim paintnow As Boolean
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_DblClick()
Cls
End Sub
Private Sub Form_Load()
DrawWidth = 4
ForeColor = RGB(255,0,0)
End Sub
Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As
Single)
paintnow = True
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As
Single)
If paintnow Then
PSet (X,Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As Single,Y As
Single)
paintnow = False
End Sub
Dim trace As Boolean
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X
As Single,Y As Single)
r = Rnd * 800
If r < 200 Then r = 200
trace = True
Circle (X,Y),r
End Sub
Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As
Single,Y As Single)
trace = False
End Sub
程序代码( form3)
Private Sub Command1_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_Click()
MouseIcon = LoadPicture("f:\djks\ppt\on.ico")
End Sub
Private Sub Picture1_Click()
picture1.Picture = LoadPicture("f:\djks\ppt\hn.jpg")
End Sub
程序代码( form4)
多窗体程序的保存与执行
设置工程的启动窗体,如果没有启动窗体或过程的话,工程将无法运行,
执行方法如下:
工程?工程 1属性,打开如下窗口,在其中选择启动对象。
保存多窗体:在新建工程中直接保存即可(要同时保存 工程 和 窗体 )
装入工程,打开工程即可,无须每个窗体打开一次。
工程的扩展名 vbp
窗体的扩展名 frm
注意:可以从最新和现存中选择,以最快速度地找到你的工程文件
Visual basic 工程结构
包括标准模块、窗体模块和 sub main 过程
如:
下列选项中,不属于 vb主要模块的是:
A 标准模块 C 工程模块
B 窗体模块 D 类模块
答案是:
完整的应用程序的组成:结构图工程组
VBG
工程 vbp
工程 vbp
工程 vbp…
标准模块 bas
窗体模块 frm
类模块 cls
全局变量声明模块层声明
Sub main过程通用过程窗体层声明通用过程事件过程闲置循环与 doevents语句
闲置:无事件在触发时 忙碌:正在执行某事件触发程序
闲置循环,idle loop:在空闲时用一个循环来执行其他操作,就是在闲置情况执行的循环。闲置循环时,cpu全部占用,要夺回 cpu控制权,用
doevents来实现。 Doevens 即可作为语句,也可作为函数。例如:
Private Sub Command1_Click()
FontSize = 12
Print "执行按钮 1的单击事件过程 "
For i = 1 To 10000
x = x * 2
Next i
End Sub
Private Sub Command3_Click()
End
End Sub
Sub main()
Form1.Show
Do While DoEvents()
If Form1.Command2.Left
<= Form1.Width Then
Form1.Command2.Left =
Form1.Command2.Left + 1
Beep
Else
Form1.Command2.Left =
Form1.Left
End If
Loop
End Sub