版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、VB程序设计8.1.1实验目的1)掌握VB多重窗体程序的概念。2)掌握多重窗体程序的设计方法。3)复习各种控件的使用方法。8.1.2实验内容采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。8.1.3实验步骤实验步骤如下:Formi1)建立启动窗体界面与设置对象属性。选择“新建”工程,进入窗体设计器,在窗体中添加命 令按钮组Command1 (0) Command1 ( 5),并修改属性如图 8-1左所示。系统默认窗体 为启动窗体。FomnLefs srta wonderfuljottm ey.厂3个标准。Module12)添加窗体。选择“工程”菜单,打开“添加窗体”对话框。按“打开”按
2、钮,添加 窗体Form2Form4。添加标准模块。选择“工程”菜单,打开“添加模块”对话框。 个标准模块1按“打开”按钮,添加.Form51234口567 890+*/ruForme喻 sysfcTzi again! ,.图8-1程序界面设计3) 建立子窗体界面与设置对象属性。界面如图8-1所示,设置属性如表所示。表8-1Formi属性设置对象属性属性值说明FormiNameForm1启动窗体Cap ti onForm10)( Command1Cap ti onWho are you?1) Command1 (Cap ti ongame)Command1 ( 2Cap ti onwritebo
3、ard)3Command1 (Cap ti oncalculator4)( Command1Cap ti onbyebyePicture1autoredrawfalseLabel1cap tionLets start a won derful jour ney表8-2Form2属性设置对象属性属性值说明Form2NameForm2输入个人资料窗口Cap ti onForm2LabelllCap ti onn ameLabel12Cap ti ongenderLabel13Cap ti onIs that a girl?FreamiCap ti onhobbiescomma ndcap ti o
4、nokeyCap ti onOp tio n1Cap ti onfemaleValueTrue默认被选中Op tio n2Cap ti onmaleValueTrue默认被选中Check1Cap ti onWoWCheck2Cap ti onLeague of Lege ndsCheck3Cap ti onDungeon and FighterCheck4Cap ti onQQs peedCheck5Cap ti onfilmsCheck6Cap ti onmovie表8-3Form3属性设置对象属性属性值说明Form3NameForm3Cap ti onForm3Comma nd1Cap t
5、i onhappin essComma nd2Cap ti onbeginComma nd3Cap ti onloveComma nd4Cap ti onbeautyComma nd5Cap ti onlaughLabel1cap tionscroesLabel2Cap ti on0Timer1in terval500Timer2in terval71Form4属性设置表8-4对象属性属性值说明Form4NameForm4Cap ti onForm4Labelcap tionLabel2Cap ti on路漫漫其修远兮Label3Cap ti on吾将上下而求索TextBoxtextPictu
6、re1pictureCap ti on返回8-5表Form5属性设置对象属性属性值说明FormNameForm5Cap ti onForm5Comma nd1(09)cap ti on19,0Comma nd1(10)cap ti onComma nd2(04)cap tion+ -*/=Label2Cap ti on路漫漫其修远兮Label3Cap ti on吾将上下而求索TextBoxtext属性设置表8-6Form6对象属性属性值说明Form4NameForm6Cap ti onForm6Labelcap ti onwelcome to use this system aga in !L
7、abel2Cap ti onthankyou !Picture1pictureTimer112in terval1Timer13in terval10004) 编写代码。编写启动”窗体 form1 ( Form1 )中代码:Op ti on Exp licitDim i As In teger, ur1 As Stri ng, N As In tegerPrivate Sub Comma nd1_Click( In dex As In teger)N = IndexSelect Case NCase 0Form2.ShowMe.HideCase 1Form3.ShowMe.HideCase 2
8、Form4.ShowMe.HideCase 3Form5.ShowMe.HideCase 5Form6.ShowMe.HideEnd SelectEnd SubPrivate Sub Form_Activate()Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture2 = LoadPicture(C:UsersLQRDesktopVB.1.gif)Picture2.AutoR
9、edraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopyEnd SubPrivate Sub Timer1_Timer()On Error GoTo Err ur1 = C:UsersLQRDesktopVB. & i & .gifPicture2.Picture = LoadPicture(ur1)Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , ,
10、, vbSrcCopyExit SubErr:End Sub编写“输入个人资料”窗体 form2 ( Form2 )中的代码:Private Sub Command1_Click()If Text1.Text = Then! Then Exit Suba = InputBox(You forget to input your name ? , Attention!, Your name ! ) If a = Or a = Your nameText1.Text = aElse: Form1.ShowForm2.HideEnd IfEnd SubPrivate Sub Form_Load()-
11、Me.Height) / 2- Me.Width) / 2Me.Top = (Screen.HeightMe.Left = (Screen.WidthPicture1 = LoadPicture(C:UsersLQRDesktopVB.fei.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 3750, 4900, , , , , vbSrcCopy End Sub编写“ GAME ”窗体 form3 ( Form3 )中的代码:Dim a As Integer, i As Integer,
12、ur1 As StringPrivate Sub Command1_Click()If Command1.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command2_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command3_Click()If Command3.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd
13、SubPrivate Sub Command4_Click()If Command4.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command5_Click()If Command5.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub cw_Click()Label2 = End SubPrivate Sub Timer2_Timer(
14、)On Error GoTo Err新建文件夹 . & i & .jpgPicture1.Picture = LoadPicture(ur1)i = i + 1Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopy Exit SubErr: i = 45End SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me
15、.Width) / 2新建文件夹 .45.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer() Static x As Integer a = Int(Rnd() * 4)Select Case aCase 0Command1.BackColor = RGB(225, 0, 0)Command3.BackColor = RGB(15, 0, 0)Command4.Bac
16、kColor = RGB(15, 0, 0)Command5.BackColor = RGB(15, 0, 0)Case 1Command3.BackColor = RGB(225, 0, 0)Command1.BackColor = RGB(15, 0, 0)Command4.BackColor = RGB(15, 0, 0)Command5.BackColor = RGB(15, 0, 0)Case 2Command4.BackColor = RGB(225, 0, 0)Command1.BackColor = RGB(15, 0, 0)Command3.BackColor = RGB(1
17、5, 0, 0)Command5.BackColor = RGB(15, 0, 0)Case 3Command5.BackColor = RGB(225, 0, 0)Command1.BackColor = RGB(15, 0, 0)Command3.BackColor = RGB(15, 0, 0)Command4.BackColor = RGB(15, 0, 0)End SelectIf x 50 ThenElseTimer1.Enabled = FalseCommand5.BackColor = RGB(15, 0, 0)Command1.BackColor = RGB(15, 0, 0
18、) Command3.BackColor = RGB(15, 0, 0) Command4.BackColor = RGB(15, 0, 0) x = 0End IfEnd SubPrivate Sub tui_Click()Form1.ShowMe.HideEnd SubPrivate Sub wf_Click()MsgBoxules: & Chr(13) & Hit the different color.In the fixed time, more hits, more scores! , vbOKOnly, RuleEnd Sub编写“ writeboard ”窗体 form4 (
19、Form4 )中的代码:Private Sub N_Click()Text1.Text = End SubPrivate Sub O_Click()潃浭湯楄污杯 ?楆瑬牥 ?尠所有文件( *.* ) |*.*| 文本文件( *.TXT )|*.txt CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub S_Click()CommonDialog1.ShowSaveText1.Text = CommonDialog1.FileNameEnd
20、 SubPrivate Sub T_Click()Form1.ShowMe.HideEnd SubPrivate Sub Text1_Change()Text1.Text = Text1.TextEnd SubPrivate Sub Y_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Z_Click()CommonDialog1.Flags = 3 Or 256 CommonDialog1.ShowFont With Text1.FontName = CommonDial
21、og1.FontName.FontSize = CommonDialog1.FontSize .FontStrikethru = CommonDialog1.FontStrikethru .FontBold = CommonDialog1.FontBold .FontItalic = CommonDialog1.FontItalic .FontUnderline = CommonDialog1.FontUnderline .ForeColor = CommonDialog1.ColorEnd WithEnd SubPrivate Sub Form_Load()Me.Top = (Screen.
22、Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture1 = LoadPicture(C:UsersLQRDesktopVB.qu.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 1500, 2500, , , , , vbSrcCopyEnd Sub编写“ calculator ”窗体 form5 ( Form5 )中的代码:Dim v As BooleanDim S As IntegerDim x As
23、DoubleDim Y As DoublePrivate Sub Command1_Click(Index As Integer)If Form5.Tag = T ThenIf Index = 10 ThenText1.Text =ElseText1.Text = Command1(Index).CaptionEnd IfForm5.Tag = ElseText1.Text = Text1.Text & Command1(Index).CaptionEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer)Form5.Tag = TIf
24、v Then x = Val(Text1.Text) v = Not vElseY = Val(Text1.Text)Select Case SCase 0Text1.Text = x + YCase 1Text1.Text = x - YCase 2Text1.Text = x * YCase 3If Y 0 ThenText1.Text = x / YElse獍?硯尠傻了?不能以 0 为除数啊! ?瘠佢佋汮 ?尠提示Text1.Text = x v = FalseEnd IfCase 4 x = Val(Text1.Text)v = FalseEnd SelectEnd IfS = Ind
25、exEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2End SubPrivate Sub tui_Click()Form1.ShowMe.HideEnd SubPrivate Sub xin_Click()Text1.Text = End Sub编写结束窗体 form6 ( Form6 )中的代码:Option ExplicitDim x As Integer, Y As Integer, a As Integer, m As
26、 Long, N As LongPrivate Sub Form_Activate()Timer1.Enabled = TrueTimer3.Enabled = TrueTimer5.Enabled = TrueTimer7.Enabled = TrueTimer9.Enabled = TrueTimer11.Enabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture1 = LoadPictur
27、e(C:UsersLQRDesktopVB.qwe.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyPicture2 = LoadPicture(C:UsersLQRDesktopVB.qwe.jpg)Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyPicture3 = LoadPi
28、cture(C:UsersLQRDesktopVB.qwe.jpg)Picture3.AutoRedraw = TruePrivate Sub Timer1_Timer()If Picture1.Width + Picture1.Left = Me.ScaleWidth ThenTimer2.Enabled = TrueTimer1.Enabled = FalseElsePicture1.Left = Picture1.Left + 50End IfEnd SubPrivate Sub Timer2_Timer()If Picture1.Left 6700 ThenTimer4.Enabled = TrueTimer3.Enabled = FalseElsePicture1.Top = Picture1.Top + 50End IfEnd Su
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年下学校工作计划范文
- 《货币银行基础》课件
- 度消防安全员工作计划范文
- 健康教育工作计划中学幼儿园健康教育工作计划
- 大气压强课件
- 幼儿园角色游戏计划 幼儿园角色活动计划
- 农广校学历教育工作计划
- 2024公安消防大队年工作计划
- 服装店个人工作计划
- 北师大版四年级上册语文教学计划
- 跨学科实践活动5基于碳中和理念设计低碳行动方案九年级化学人教版上册
- 【MOOC】概率论与数理统计-重庆大学 中国大学慕课MOOC答案
- 车位租赁合同标准版可打印
- 机械工程技术训练(北京航空航天大学)知到智慧树章节答案
- 生活垃圾发电企业安全生产双体系
- 【初中化学】二氧化碳的实验室制取课件-2024-2025学年九年级化学人教版上册
- 外研版三年级起点五年级上册英语集体备课教案
- 期末 (试题) -2024-2025学年人教PEP版英语六年级上册
- 湖南省2024年普通高中学业水平合格性模拟考试数学仿真卷(六)
- 新课标背景下“教学评一体化”评的策略
- 湖南省工程建设地方标准分布式光伏工程验收标准
评论
0/150
提交评论