VB小程序制作.docx
- 文档编号:28569541
- 上传时间:2023-07-19
- 格式:DOCX
- 页数:26
- 大小:4.56MB
VB小程序制作.docx
《VB小程序制作.docx》由会员分享,可在线阅读,更多相关《VB小程序制作.docx(26页珍藏版)》请在冰豆网上搜索。
VB小程序制作
VB程序设计
8.1.1实验目的
1)掌握VB多重窗体程序的概念。
2)掌握多重窗体程序的设计方法。
3)复习各种控件的使用方法。
8.1.2实验内容
采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。
8.1.3实验步骤
实验步骤如下:
1)建立启动窗体界面与设置对象属性。
选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组Command1(0)~Command1(5),并修改属性如图8-1左所示。
系统默认窗体Form1为启动窗体。
2)添加窗体。
选择“工程”菜单,打开“添加窗体”对话框。
按“打开”按钮,添加3个标准窗体Form2~Form4。
添加标准模块。
选择“工程”菜单,打开“添加模块”对话框。
按“打开”按钮,添加1个标准模块Module1。
图8-1程序界面设计
3)建立子窗体界面与设置对象属性。
界面如图8-1所示,设置属性如表所示。
表8-1Form1属性设置
对象
属性
属性值
说明
Form1
Name
Form1
启动窗体
Caption
Form1
Command1(0)
Caption
Whoareyou?
Command1
(1)
Caption
game
Command1
(2)
Caption
writeboard
Command1(3)
Caption
calculator
Command1(4)
Caption
byebye
Picture1
autoredraw
false
Label1
caption
Let'sstartawonderfuljourney
表8-2Form2属性设置
对象
属性
属性值
说明
Form2
Name
Form2
输入个人资料窗口
Caption
Form2
Label11
Caption
name
Label12
Caption
gender
Label13
Caption
Isthatagirl?
Fream1
Caption
hobbies
command
caption
okey
Caption
Option1
Caption
female
Value
True
默认被选中
Option2
Caption
male
Value
True
默认被选中
Check1
Caption
WoW
Check2
Caption
LeagueofLegends
Check3
Caption
DungeonandFighter
Check4
Caption
QQspeed
Check5
Caption
films
Check6
Caption
movie
表8-3Form3属性设置
对象
属性
属性值
说明
Form3
Name
Form3
Caption
Form3
Command1
Caption
happiness
Command2
Caption
begin
Command3
Caption
love
Command4
Caption
beauty
Command5
Caption
laugh
Label1
caption
scroes
Label2
Caption
0
Timer1
interval
500
Timer2
interval
71
表8-4Form4属性设置
对象
属性
属性值
说明
Form4
Name
Form4
Caption
Form4
Label
caption
Label2
Caption
路漫漫其修远兮
Label3
Caption
吾将上下而求索
TextBox
text
Picture1
picture
Caption
返回
表8-5Form5属性设置
对象
属性
属性值
说明
Form
Name
Form5
Caption
Form5
Command1(0~9)
caption
1~9,0
Command1(10)
caption
.
Command2(0~4)
caption
+-*/=
Label2
Caption
路漫漫其修远兮
Label3
Caption
吾将上下而求索
TextBox
text
表8-6Form6属性设置
对象
属性
属性值
说明
Form4
Name
Form6
Caption
Form6
Label
caption
welcometousethissystemagain!
!
Label2
Caption
thankyou!
Picture1
picture
Timer1~12
interval
1
Timer13
interval
1000
4)编写代码。
编写“启动”窗体form1(Form1)中代码:
OptionExplicit
DimiAsInteger,ur1AsString,NAsInteger
PrivateSubCommand1_Click(IndexAsInteger)
N=Index
SelectCaseN
Case0
Form2.Show
Me.Hide
Case1
Form3.Show
Me.Hide
Case2
Form4.Show
Me.Hide
Case3
Form5.Show
Me.Hide
Case5
Form6.Show
Me.Hide
EndSelect
EndSub
PrivateSubForm_Activate()
Timer1.Enabled=True
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
Picture2=LoadPicture("C:
\Users\LQR\Desktop\VB.\1.gif")
Picture2.AutoRedraw=True
Picture2.PaintPicturePicture2.Picture,0,0,3000,3000,,,,,vbSrcCopy
EndSub
PrivateSubTimer1_Timer()
OnErrorGoToErr
ur1="C:
\Users\LQR\Desktop\VB.\"&i&".gif"
Picture2.Picture=LoadPicture(ur1)
i=i+1
Picture2.AutoRedraw=True
Picture2.PaintPicturePicture2.Picture,0,0,3000,3000,,,,,vbSrcCopy
ExitSub
Err:
i=1
EndSub
编写“输入个人资料”窗体form2(Form2)中的代码:
PrivateSubCommand1_Click()
IfText1.Text=""Then
a=InputBox("Youforgettoinputyourname?
","Attention!
","Yourname!
")
Ifa=""Ora="Yourname!
"ThenExitSub
Text1.Text=a
Else:
Form1.Show
Form2.Hide
EndIf
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
Picture1=LoadPicture("C:
\Users\LQR\Desktop\VB.\fei.jpg")
Picture1.AutoRedraw=True
Picture1.PaintPicturePicture1.Picture,0,0,3750,4900,,,,,vbSrcCopy
EndSub
编写“GAME”窗体form3(Form3)中的代码:
DimaAsInteger,iAsInteger,ur1AsString
PrivateSubCommand1_Click()
IfCommand1.BackColor=RGB(225,0,0)Then
Label2=Val(Label2.Caption)+1
EndIf
EndSub
PrivateSubCommand2_Click()
Timer1.Enabled=True
EndSub
PrivateSubCommand3_Click()
IfCommand3.BackColor=RGB(225,0,0)Then
Label2=Val(Label2.Caption)+1
EndIf
EndSub
PrivateSubCommand4_Click()
IfCommand4.BackColor=RGB(225,0,0)Then
Label2=Val(Label2.Caption)+1
EndIf
EndSub
PrivateSubCommand5_Click()
IfCommand5.BackColor=RGB(225,0,0)Then
Label2=Val(Label2.Caption)+1
EndIf
EndSub
PrivateSubcw_Click()
Label2=""
EndSub
PrivateSubTimer2_Timer()
OnErrorGoToErr
ur1="C:
\Users\LQR\Desktop\新建文件夹.\"&i&".jpg"
Picture1.Picture=LoadPicture(ur1)
i=i+1
Picture1.AutoRedraw=True
Picture1.PaintPicturePicture1.Picture,0,0,12135,8295,,,,,vbSrcCopy
ExitSub
Err:
i=45
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
Picture1=LoadPicture("C:
\Users\LQR\Desktop\新建文件夹.\45.jpg")
Picture1.AutoRedraw=True
Picture1.PaintPicturePicture1.Picture,0,0,12135,8295,,,,,vbSrcCopy
EndSub
PrivateSubTimer1_Timer()
StaticxAsInteger
a=Int(Rnd()*4)
SelectCasea
Case0
Command1.BackColor=RGB(225,0,0)
Command3.BackColor=RGB(15,0,0)
Command4.BackColor=RGB(15,0,0)
Command5.BackColor=RGB(15,0,0)
Case1
Command3.BackColor=RGB(225,0,0)
Command1.BackColor=RGB(15,0,0)
Command4.BackColor=RGB(15,0,0)
Command5.BackColor=RGB(15,0,0)
Case2
Command4.BackColor=RGB(225,0,0)
Command1.BackColor=RGB(15,0,0)
Command3.BackColor=RGB(15,0,0)
Command5.BackColor=RGB(15,0,0)
Case3
Command5.BackColor=RGB(225,0,0)
Command1.BackColor=RGB(15,0,0)
Command3.BackColor=RGB(15,0,0)
Command4.BackColor=RGB(15,0,0)
EndSelect
Ifx<50Then
x=x+1
Else
Timer1.Enabled=False
Command5.BackColor=RGB(15,0,0)
Command1.BackColor=RGB(15,0,0)
Command3.BackColor=RGB(15,0,0)
Command4.BackColor=RGB(15,0,0)
x=0
EndIf
EndSub
PrivateSubtui_Click()
Form1.Show
Me.Hide
EndSub
PrivateSubwf_Click()
MsgBox"rules:
"&Chr(13)&"Hitthedifferentcolor.Inthefixedtime,morehits,morescores!
!
",vbOKOnly,"Rule"
EndSub
编写“writeboard”窗体form4(Form4)中的代码:
PrivateSubN_Click()
Text1.Text=""
EndSub
PrivateSubO_Click()
CommonDialog1.Filter="所有文件(*.*)|*.*|文本文件(*.TXT)|*.txt"
CommonDialog1.FilterIndex=1
CommonDialog1.ShowOpen
Text1.Text=CommonDialog1.FileName
EndSub
PrivateSubS_Click()
CommonDialog1.ShowSave
Text1.Text=CommonDialog1.FileName
EndSub
PrivateSubT_Click()
Form1.Show
Me.Hide
EndSub
PrivateSubText1_Change()
Text1.Text=Text1.Text
EndSub
PrivateSubY_Click()
CommonDialog1.ShowColor
Text1.ForeColor=CommonDialog1.Color
EndSub
PrivateSubZ_Click()
CommonDialog1.Flags=3Or256
CommonDialog1.ShowFont
WithText1
.FontName=CommonDialog1.FontName
.FontSize=CommonDialog1.FontSize
.FontStrikethru=CommonDialog1.FontStrikethru
.FontBold=CommonDialog1.FontBold
.FontItalic=CommonDialog1.FontItalic
.FontUnderline=CommonDialog1.FontUnderline
.ForeColor=CommonDialog1.Color
EndWith
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
Picture1=LoadPicture("C:
\Users\LQR\Desktop\VB.\qu.jpg")
Picture1.AutoRedraw=True
Picture1.PaintPicturePicture1.Picture,0,0,1500,2500,,,,,vbSrcCopy
EndSub
编写“calculator”窗体form5(Form5)中的代码:
DimvAsBoolean
DimSAsInteger
DimxAsDouble
DimYAsDouble
PrivateSubCommand1_Click(IndexAsInteger)
IfForm5.Tag="T"Then
IfIndex=10Then
Text1.Text="0"
Else
Text1.Text=Command1(Index).Caption
EndIf
Form5.Tag=""
Else
Text1.Text=Text1.Text&Command1(Index).Caption
EndIf
EndSub
PrivateSubCommand2_Click(IndexAsInteger)
Form5.Tag="T"
IfvThen
x=Val(Text1.Text)
v=Notv
Else
Y=Val(Text1.Text)
SelectCaseS
Case0
Text1.Text=x+Y
Case1
Text1.Text=x-Y
Case2
Text1.Text=x*Y
Case3
IfY<>0Then
Text1.Text=x/Y
Else
MsgBox"傻了?
不能以0为除数啊!
",vbOKOnly,"提示"
Text1.Text=x
v=False
EndIf
Case4
Y=0
v=False
EndSelect
x=Val(Text1.Text)
EndIf
S=Index
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
EndSub
PrivateSubtui_Click()
Form1.Show
Me.Hide
EndSub
PrivateSubxin_Click()
Text1.Text=""
EndSub
编写结束窗体form6(Form6)中的代码:
OptionExplicit
DimxAsInteger,YAsInteger,aAsInteger,mAsLong,NAsLong
PrivateSubForm_Activate()
Timer1.Enabled=True
Timer3.Enabled=True
Timer5.Enabled=True
Timer7.Enabled=True
Timer9.Enabled=True
Timer11.Enabled=True
EndSub
PrivateSubForm_Load()
Me.Top=(Screen.Height-Me.Height)/2
Me.Left=(Screen.Width-Me.Width)/2
Picture1=LoadPicture("C:
\Users\LQR\Desktop\VB.\qwe.jpg")
Picture1.AutoRedraw=True
Picture1.PaintPicturePicture1.Picture,0,0,2250,2250,,,,,vbSrcCopy
Picture2=LoadPicture("C:
\Users\LQR\Desktop\VB.\qwe.jpg")
Picture2.AutoRedraw=True
Picture2.PaintPicturePicture2.Picture,0,0,2250,2250,,,,,vbSrcCopy
Picture3=LoadPicture("C:
\Users\LQR\Desktop\VB.\qwe.jpg")
Picture3.AutoRedraw=True
Picture3.PaintPicturePicture3.Picture,0,0,2250,2250,,,,,vbSrcCopy
EndSub
PrivateSubTimer1_Timer()
IfPicture1.Width+Picture1.Left>=Me.ScaleWidthThen
Timer2.Enabled=True
Timer1.Enabled=False
Else
Picture1.Left=Picture1.Left+50
EndIf
EndSub
PrivateSubTimer2_Timer()
IfPicture1.Left<=0Then
Timer1.Enabled=True
Timer2.Enabled=False
Else
Picture1.Left=Picture1.Left-50
EndIf
EndSub
PrivateSubTimer3_Timer()
IfPicture1.Top+Picture1.Height>6700Then
Timer4.Enabled=True
Timer3.Enabled=False
Else
Picture1.Top=Picture1.Top+50
EndIf
EndSub
PrivateSubTimer4_Timer()
If
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 程序 制作