版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、VB程序设计8.1.1实验目的1)掌握VB多重窗体程序的概念。2)掌握多重窗体程序的设计方法。3)复习各种控件的使用方法。采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。8.1.3实验步骤实验步骤如下:1)建立启动窗体界面与设置对象届性。选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组Commandl (0) Command1 (5),并修改届性如图8-1左所示。系统默认窗体 Forml为启动窗体。2) 添加窗体。选择“工程”菜单,打开“添加窗体”对话框。按“打开”按钮,添加3个标准窗体Form2Form4。添加标准模块。选择“工程”菜单,打开“添加模块”对话框。按“打开”按钮
2、,添加1个标准模块Module1。图8-1程序界面设计3)建立子窗体界面与设置对象届性。界面如图8-1所示,设置届性如表所示表8-1Form1属性设置对象届性届性值说明Form1NameForm1启动窗体CaptionForm1Command1 (0)CaptionWhoareyou?Command1 (1)CaptiongameCommand1 (2)CaptionwriteboardCommand1 (3)CaptioncalculatorCommand1 (4)CaptionbyebyePicture1autoredrawfalseLabel1captionLet'sstarta
3、wonderfu ljourney表8-2Form2属性设置对象届性届性值说明Form2NameForm2输入个人资料窗 口CaptionForm2Label11CaptionnameLabel12CaptiongenderLabel13CaptionIsthatagirl?Fream1CaptionhobbiescommandcaptionokeyCaptionOption1CaptionfemaleValueTrue默认被选中Option2CaptionmaleValueTrue默认被选中ChecklCaptionWoWCheck2CaptionLeagueofLegendsCheck3C
4、aptionDungeonandFighte rCheck4CaptionQQspeedCheck5CaptionfilmsCheck6Captionmovie表8-3 Form3属性设置对象届性届性值说明Form3NameForm3CaptionForm3Command1CaptionhappinessCommand2CaptionbeginCommand3CaptionloveCommand4CaptionbeautyCommand5CaptionlaughLabel1captionscroesJ 如“,Label2Caption0 1 x'x'',_-* y
5、9; 一 Timer1interval500j i' i y' j."_Timer2interval71y. j表8-4Form4属性设置对象届性届性值说明Form4NameForm4CaptionForm4Labelcaption1 iLabel2Caption路漫漫其修远兮Label3Caption吾将上卜而求索TextBoxtextPicture1pictureCaption返回表8-5 Form5属性设置对象j届性届性值说明FormNameForm5CaptionForm5Command1(09)caption19,0Command1(10)caption.C
6、ommand2(04)caption+-*/=Label2Caption路漫漫其修远兮Label3Caption吾将上卜而求索TextBoxtext表8-6 Form6属性设置对象届性届性值说明Form4NameForm6来源网络CaptionForm6Labelcaptionwelcometousethiss ystemagain!Label2Captionthankyou!Picture1pictureTimer112interval1Timer13interval10004)编写代码。编写“启动”窗体forml (Forml)中代码:OptionExplicitDimiAsInteger
7、,ur1AsString,NAsIntegerPrivateSubCommand1_Click(IndexAsInteger)N=IndexSelectCaseNCase0 孚* Form2.ShowMe.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()
8、Me.Top=(Screen.Height-Me.Height)/2 Me.Left=(Screen.Width-Me.Width)/2 Picture2=LoadPicture("C:UsersLQRDesktopVB.1.gif") Picture2.AutoRedraw=TruePicture2.PaintPicturePicture2.Picture,0,0,3000,3000,vbSrcCopy EndSubPrivateSubTimer1_Timer() OnErrorGoToErr ur1="C:UsersLQRDesktopVB."&am
9、p;i&".gif" Picture2.Picture=LoadPicture(ur1) i=i+1 来源网络Picture2.AutoRedraw=TruePicture2.PaintPicturePicture2.Picture,0,0,3000,3000,vbSrcCopy ExitSubErr: i=1 EndSub编写“输入个人资料”窗体form2 (Form2)中的代码: PrivateSubCommand1_Click()IfText1.Text=""Thena=InputBox("Youforgettoinputyour
10、name ? ”,"Attention!”,"Yourname !")Ifa=""Ora="Yourname ! "ThenExitSubText1.Text=aElse:Form1.ShowForm2.HideEndIfEndSubPrivateSubForm_Load()Me.Top=(Screen.Height-Me.Height)/2 Me.Left=(Screen.Width-Me.Width)/2 Picture1=LoadPicture("C:UsersLQRDesktopVB.fei.jpg&quo
11、t;) Picture1.AutoRedraw=TruePicture1.PaintPicturePicture1.Picture,0,0,3750,4900,vbSrcCopy EndSub编写“GAME”窗体form3 (Form3)中的代码: DimaAsInteger,iAsInteger,ur1AsString PrivateSubCommand1_Click()IfCommand1.BackColor=RGB(225,0,0)ThenLabel2=Val(Label2.Caption)+1EndIfEndSubPrivateSubCommand2_Click()Timer1.Ena
12、bled=TrueEndSubPrivateSubCommand3_Click()IfCommand3.BackColor=RGB(225,0,0)ThenLabel2=Val(Label2.Caption)+1EndIfEndSubPrivateSubCommand4_Click()IfCommand4.BackColor=RGB(225,0,0)ThenLabel2=Val(Label2.Caption)+1EndIfEndSubPrivateSubCommand5_Click()IfCommand5.BackColor=RGB(225,0,0)Then Label2=Val(Label2
13、.Caption)+1 来源网络EndIf EndSub PrivateSubcw_Click() Label2="" EndSubPrivateSubTimer2_Timer() OnErrorGoToErr新建文件夹."&i&".jpg" Picture1.Picture=LoadPicture(ur1) i=i+1Picture1.AutoRedraw=True Picture1.PaintPicturePicture1.Picture,0,0,12135,8295,vbSrcCopy ExitSubErr: i=45 E
14、ndSub PrivateSubForm_Load() Me.Top=(Screen.Height-Me.Height)/2 Me.Left=(Screen.Width-Me.Width)/2新建文件夹.45.jpg") Picture1.AutoRedraw=TruePicture1.PaintPicturePicture1.Picture,0,0,12135,8295,vbSrcCopy EndSubPrivateSubTimer1_Timer() StaticxAsInteger a=Int(Rnd()*4) SelectCaseaCase0 Command1.BackColo
15、r=RGB(225,0,0) Command3.BackColor=RGB(15,0,0) Command4.BackColor=RGB(15,0,0) Command5.BackColor=RGB(15,0,0) Case1Command3.BackColor=RGB(225,0,0) Command1.BackColor=RGB(15,0,0) Command4.BackColor=RGB(15,0,0) Command5.BackColor=RGB(15,0,0) Case2Command4.BackColor=RGB(225,0,0) Command1.BackColor=RGB(15
16、,0,0) Command3.BackColor=RGB(15,0,0) Command5.BackColor=RGB(15,0,0) Case3Command5.BackColor=RGB(225,0,0) Command1.BackColor=RGB(15,0,0) Command3.BackColor=RGB(15,0,0) 来源网络Command4.BackColor=RGB(15,0,0)EndSelectIfx<50Thenx=x+1ElseTimer1.Enabled=FalseCommand5.BackColor=RGB(15,0,0)Command1.BackColor
17、=RGB(15,0,0)Command3.BackColor=RGB(15,0,0)Command4.BackColor=RGB(15,0,0)x=0EndIfEndSubPrivateSubtui_Click()Form1.ShowMe.HideEndSubPrivateSubwf_Click()MsgBox"rules: "&Chr(13)&"Hitthedifferentcolor.Inthefixedtime,morehits,morescores ! !",vbOKOnly,"Rule"EndSub编写 “w
18、riteboard”窗体 form4 (Form4)中的代码:PrivateSubN_Click()Text1.Text=""EndSubPrivateSubO_Click()CommonDialog1.Filter=”所有文件(*.* ) |*.*| 文本文件(*.TXT ) |*.txt”CommonDialog1.FilterIndex=1CommonDialog1.ShowOpenText1.Text=CommonDialog1.FileNameEndSubPrivateSubS_Click()CommonDialog1.ShowSaveText1.Text=Com
19、monDialog1.FileNameEndSubPrivateSubT_Click()Form1.ShowMe.Hide EndSub PrivateSubText1_Change() Text1.Text=Text1.Text EndSub PrivateSubY_Click() CommonDialog1.ShowColor Text1.ForeColor=CommonDialog1.Color EndSub 来源网络PrivateSubZ_Click()CommonDialog1.Flags=3Or256CommonDialogl.ShowFontWithText1.FontName=
20、CommonDialog1.FontName.FontSize=CommonDialog1.FontSize.FontStrikethru=CommonDialog1.FontStrikethru.FontBold=CommonDialog1.FontBold.FontItalic=CommonDialog1.FontItalic.FontUnderline=CommonDialog1.FontUnderline.ForeColor=CommonDialog1.ColorEndWithEndSubPrivateSubForm_Load()Me.Top=(Screen.Height-Me.Hei
21、ght)/2Me.Left=(Screen.Width-Me.Width)/2Picture1=LoadPicture("C:UsersLQRDesktopVB.qu.jpg")Picture1.AutoRedraw=TruePicture1.PaintPicturePicture1.Picture,0,0,1500,2500,vbSrcCopyEndSub编写 “calculator” 窗体 form5 (Form5)中的代码:DimvAsBooleanDimSAsIntegerDimxAsDoubleDimYAsDoublePrivateSubCommand1_Clic
22、k(IndexAsInteger)IfForm5.Tag="T"ThenIfIndex=10ThenText1.Text="0"ElseText1.Text=Command1(Index).CaptionEndIfForm5.Tag=""ElseText1.Text=Text1.Text&Command1(Index).CaptionEndIfEndSubPrivateSubCommand2_Click(IndexAsInteger)Form5.Tag="T"IfvThenx=Val(Text1.Text)
23、v=NotvElse Y=Val(Text1.Text) SelectCaseS Case0 来源网络Text1.Text=x+YCaselText1.Text=x-YCase2Text1.Text=x*YCase3IfY<>0ThenText1.Text=x/YElseMsgBox"傻了?不能以0为除数啊! ",vbOKOnly,"提示"Text1.Text=xv=FalseEndIfCase4Y=0v=FalseEndSelectx=Val(Text1.Text)EndIfS=IndexEndSubPrivateSubForm_Load(
24、)Me.Top=(Screen.Height-Me.Height)/2Me.Left=(Screen.Width-Me.Width)/2EndSubPrivateSubtui_Click()Form1.ShowMe.HideEndSubPrivateSubxin_Click()Text1.Text=""EndSub编写结束窗体form6 (Form6)中的代码: OptionExplicitDimxAsInteger,YAsInteger,aAsInteger,mAsLong,NAsLongPrivateSubForm_Activate()Timer1.Enabled=Tr
25、ueTimer3.Enabled=TrueTimer5.Enabled=TrueTimer7.Enabled=TrueTimer9.Enabled=TrueTimer11.Enabled=TrueEndSubPrivateSubForm_Load()Me.Top=(Screen.Height-Me.Height)/2 Me.Left=(Screen.Width-Me.Width)/2 来源网络Picture1=LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture1.AutoRedraw=TruePicture1.PaintPic
26、turePicture1.Picture,0,0,2250,2250,vbSrcCopyPicture2=LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture2.AutoRedraw=TruePicture2.PaintPicturePicture2.Picture,0,0,2250,2250,vbSrcCopyPicture3=LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture3.AutoRedraw=TruePicture3.PaintPicturePict
27、ure3.Picture,0,0,2250,2250,vbSrcCopyEndSubPrivateSubTimer1_Timer()IfPicture1.Width+Picture1.Left>=Me.ScaleWidthThenTimer2.Enabled=TrueTimer1.Enabled=FalseElsePicture1.Left=Picture1.Left+50EndIfEndSubPrivateSubTimer2_Timer()IfPicture1.Left<=0ThenTimer1.Enabled=TrueTimer2.Enabled=FalseElsePictur
28、e1.Left=Picture1.Left-50EndIfEndSubPrivateSubTimer3_Timer()IfPicture1.Top+Picture1.Height>6700ThenTimer4.Enabled=TrueTimer3.Enabled=FalseElsePicture1.Top=Picture1.Top+50EndIfEndSubPrivateSubTimer4_Timer()IfPicture1.Top<0ThenTimer3.Enabled=TrueTimer4.Enabled=FalseElsePicture1.Top=Picture1.Top-5
29、0EndIfEndSubPrivateSubTimer5_Timer()IfPicture2.Width+Picture2.Left>=Me.ScaleWidthThenTimer6.Enabled=TrueTimer5.Enabled=False来源网络Else Picture2.Left=Picture2.Left+50 EndIf EndSub PrivateSubTimer6_Timer() IfPicture2.Left<=0Then Timer5.Enabled=True Timer6.Enabled=False Else Picture2.Left=Picture2.Left-50 EndIfEndSub PrivateSubTimer7_Timer() IfPicture2.Top+Picture2.Hei
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度新型能源汽车短期借用协议书4篇
- 2025年度文化产业发展基金投资合作合同4篇
- 2025年度智能家居橱柜定制工程协议书4篇
- 2025年度新能源车辆租赁代理合同模板3篇
- 2024版离婚协议年范本
- 2025年单梁桥式起重机项目可行性研究报告-20250102-152444
- 2025年中盐青海昆仑碱业有限公司招聘笔试参考题库含答案解析
- 2025年四川壮禾人力资源有限公司招聘笔试参考题库含答案解析
- 2025年中国邮政证券有限责任公司招聘笔试参考题库含答案解析
- 2025年江苏弘景建设规划有限公司招聘笔试参考题库含答案解析
- 漆画漆艺 第三章
- CB/T 615-1995船底吸入格栅
- 光伏逆变器一课件
- 货物供应、运输、包装说明方案
- (完整版)英语高频词汇800词
- 《基础马来语》课程标准(高职)
- IEC61850研讨交流之四-服务影射
- 《儿科学》新生儿窒息课件
- 材料力学压杆稳定
- 人教版小升初英语知识点汇总
- 静态爆破专项施工方案
评论
0/150
提交评论