版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、VB程序设计& 1.1实验目的1)掌握VB多重窗体程序的概念。2)掌握多重窗体程序的设计方法。3)复习各种控件的使用方法。采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。8.1.3实验步骤实验步骤如下:1)建立启动窗体界面与设置对象属性。选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组 Command1 (0) Command1 (5),并修改属性如图8-1左所示。系统默认窗体Forml为启动窗体。2) 添加窗体。选择“工程”菜单,打开“添加窗体”对话框。按“打开”按钮,添加3个标准 窗体Form2Form4。添加标准模块。选择“工程”菜单,打开“添加模块”对话框。按“打开按钮
2、,添加1个标准模块 Modulel。图8-1程序界面设计3) 建立子窗体界面与设置对象属性。界面如图8-1所示,设置属性如表所示。表8-1 Form1属性设置对象属性属性值说明Form1NameForm1启动窗体Capti onForm1Comma nd1 ( 0)Capti onWho are you?Comma nd1 ( 1)Capti ongameComma nd1 ( 2)Capti onwriteboardComma nd1 ( 3)Capti oncalculatorComma nd1 ( 4)Capti onbyebyePicture1autoredrawfalseLabel1
3、capti onLets start a wonderful journey表8-2Form2属性设置对象属性属性值说明Form2NameForm2输入个人资料窗口Capti onForm2Label11Capti onn ameLabel12Capti ongenderLabel13Capti onIs that a girl?Fream1Capti onhobbiescomma ndcapti onokeyCapti onOptio n1Capti onfemaleValueTrue默认被选中Optio n2Capti onmaleValueTrue默认被选中ChecklCapti onW
4、oWCheck2Capti onLeague of Lege ndsCheck3Capti onDungeon and FighterCheck4Capti onQQspeedCheck5Capti onfilmsCheck6Capti onmovie表8-3 Form3属性设置对象属性属性值说明Form3NameForm3Capti onForm3Comma nd1Capti onhapp in essComma nd2Capti onbeginComma nd3Capti onloveComma nd4Capti onbeautyComma nd5Capti onlaughLabel1ca
5、pti onscroesLabel2Capti on0Timer1in terval500Timer2in terval71表8-4Form4属性设置对象属性属性值说明Form4NameForm4Capti onForm4Labelcapti onLabel2Capti on路漫漫其修远兮Label3Capti on吾将上下而求索TextBoxtextPicture1pictureCapti on返回表8-5 Form5属性设置对象属性属性值说明FormNameForm5Capti onForm5Comma nd1(09)capti on19,0Comma nd1(10)capti onCom
6、ma nd2(04)capti on+-*/=Label2Capti on路漫漫其修远兮Label3Capti on吾将上下而求索TextBoxtext表8-6 Form6属性设置对象属性属性值说明Form4NameForm6Capti onForm6Labelcapti onwelcome to use this system aga in !Label2Capti ontha nk you !PicturelpictureTimer112in terval1Timer13in terval10004)编写代码。编写启动”窗体 forml ( Forml )中代码:Opti on Expli
7、citDim i As Integer, ur1 As String, N As IntegerPrivate Sub Comma nd1_Click(l ndex As In teger)N = In dexSelect Case NCase 0Form2.ShowMe.HideCase 1Form3.ShowMe.HideCase 2Form4.ShowMe.HideCase 3Form5.ShowMe.HideCase 5Form6.ShowMe.HideEnd SelectI End SubPrivate Sub Form_Activate()Timer1.E nabled = Tru
8、eEnd SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me Left = (Scree n. Width - Me.Width) / 2Picture2 = LoadPictureCCUsersLQRDesktopVB.1.gif)Picture2.AutoRedraw = TruePicture2.Pai ntPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer()On
9、Error GoTo Errur1 = C:UsersLQRDesktopVB. & i & .gifPicture2.Picture = LoadPicture(url)i = i + 1Picture2.AutoRedraw = TruePicture2.Pai ntPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopyExit SubErr:i = 1End Sub编写输入个人资料”窗体form2 ( Form2 )中的代码:Private Sub Comma nd1_Click()If Text1.Text = The
10、 na = In putBox(You forget to in put your n ame? , Atte nti on!, Your n ame !)If a = Or a = Your name ! Then Exit SubText1.Text = aElse: Form1.ShowForm2.HideEnd IfEnd SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me Left = (Scree n. Width - Me.Width) / 2Picture1 = LoadPictureCCU
11、sersLQRDesktopVB.fei.jpg)Picture1.AutoRedraw = TruePicture1.Pai ntPicture Picture1.Picture, 0, 0, 3750, 4900, , , , , vbSrcCopyEnd Sub编写GAME ”窗体form3 ( Form3 )中的代码:Dim a As In teger, i As In teger, ur1 As Stri ngPrivate Sub Comma nd1_Click()If Comma nd1.BackColor = RGB(225, 0, 0) The nLabel2 = Val(L
12、abel2.Captio n) + 1End肩End SubPrivate Sub Comma nd2_Click()Timer1.E nabled = TrueEnd SubPrivate Sub Comma nd3_Click()If Comma nd3.BackColor = RGB(225, 0, 0) The nLabel2 = Val(Label2.Captio n) + 1End IfEnd SubPrivate Sub Comma nd4_Click()If Comma nd4.BackColor = RGB(225, 0, 0) The nLabel2 = Val(Label
13、2.Captio n) + 1End IfEnd SubPrivate Sub Comma nd5_Click()If Command5.BackColor = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Captio n) + 1End IfEnd SubPrivate Sub cw_Click()Label2 =End SubPrivate Sub Timer2_Timer()On Error GoTo Err新建文件夹. & i & .jpgPicture1.Picture = LoadPicture(ur1)i = i + 1Picture1.Auto
14、Redraw = TruePicture1.Pai ntPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopyExit SubErr:i = 45End SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me Left = (Scree n. Width - Me.Width) / 2新建文件夹.45.jpg)Picture1.AutoRedraw = TruePicture1.Pai ntPicture Picture1.Picture,
15、0, 0, 12135, 8295, , , , , vbSrcCopyEnd SubPrivate Sub Timer1_Timer()Static x As In tegera = Int(Rnd() * 4)Select Case aCase 0Comma nd1.BackColor = RGB(225, 0, 0)Comma nd3.BackColor = RGB(15, 0, 0)Comma nd4.BackColor = RGB(15, 0, 0)Comma nd5.BackColor = RGB(15, 0, 0)Case 1Comma nd3.BackColor = RGB(2
16、25, 0, 0)Comma nd1.BackColor = RGB(15, 0, 0)Comma nd4.BackColor = RGB(15, 0, 0)Comma nd5.BackColor = RGB(15, 0, 0)Case 2Comma nd4.BackColor = RGB(225, 0, 0)Comma nd1.BackColor = RGB(15, 0, 0)Command3.BackColor = RGB(15, 0, 0)Comma nd5.BackColor = RGB(15, 0, 0)Case 3Comma nd5.BackColor = RGB(225, 0,
17、0)Comma ndl.BackColor = RGB(15, 0, 0)Comma nd3.BackColor = RGB(15, 0, 0)Comma nd4.BackColor = RGB(15, 0, 0)End SelectIf x 50 The nx = x + 1ElseTimer1.E nabled = FalseComma nd5.BackColor = RGB(15, 0, 0)Comma nd1.BackColor = RGB(15, 0, 0)Comma nd3.BackColor = RGB(15, 0, 0)Comma nd4.BackColor = RGB(15,
18、 0, 0)x = 0End IfEnd SubPrivate Sub tui_Click()Form1.ShowMe.HideEnd SubPrivate Sub wf_Click()MsgBox rules : & Chr(13) & Hit the different color.In the fixed time, more hits, morescores! , vbOKOnly, RuleEnd Sub编写writeboard ”窗体 form4 ( Form4)中的代码:Private Sub N_Click()Text1.Text =End SubPrivate Sub O_C
19、lick()CommonDialog1.Filter =所有文件(* ) |*| 文本文件(*.TXT ) |*.txtCommon Dialog1.Filterl ndex = 1Common Dialog1.ShowOpe nText1.Text = Common Dialog1.FileNameEnd SubPrivate Sub S_Click()Common Dialog1.ShowSaveText1.Text = Common Dialog1.FileNameEnd SubPrivate Sub T_Click()Form1.ShowMe.HideEnd SubPrivate Su
20、b Text1_Cha nge()Textl.Text = Text1.TextEnd SubPrivate Sub Y_Click()Commo nDialog1.ShowColorText1.ForeColor = Com mon Dialog1.ColorEnd SubPrivate Sub Z_Click()Com mon Dialog1.Flags = 3 Or 256Com mon Dialog1.ShowF ontWith Text1.Fon tName = Common Dialog1.F on tName.Fon tSize = Common Dialog1.F on tSi
21、ze.Fo ntStrikethru = Com mon Dialog1.F on tStrikethru.Fo ntBold = Commo nDialog1.Fo ntBold.Fon tItalic = Com mon Dialog1.F on tItalic.Fo ntUn derli ne = Com mon Dialog1.F ontUn derli ne.ForeColor = Common Dialog1.ColorEnd WithEnd SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me
22、Left = (Scree n. Width - Me.Width) / 2Picture1 = LoadPictureCCUsersLQRDesktopVB.qu.jpg)Picture1.AutoRedraw = TruePicture1.Pa in tPicture Picture1.Picture, 0, 0, 1500, 2500, , , , , vbSrcCopy End Sub编写calculator ”窗体 form5 ( Form5)中的代码:Dim v As Boolea nDim S As In tegerDim x As DoubleDim Y As DoublePr
23、ivate Sub Comma nd1_Click(l ndex As In teger)If Form5.Tag = T The nIf In dex = 10 The nTextl.Text = 0ElseTextl.Text = Comma nd1(l ndex).Capti onEnd IfForm5.Tag =ElseTextl.Text = Textl.Text & Comma nd1(l ndex).Captio nEnd IfEnd SubPrivate Sub Comma nd2_Click(l ndex As In teger)Form5.Tag = TIf v The n
24、x = Val(Textl.Text)v = Not vElseY = Val(Textl.Text)Select Case SCase 0Textl.Text = x + YCase 1Textl.Text = x - YCase 2Textl.Text = x * YCase 3If Y 0 The nTextl.Text = x / YElseMsgBox 傻了?不能以 0为除数啊!, vbOKOnly,提示“Textl.Text = xv = FalseEnd IfCase 4Y = 0v = FalseEnd Selectx = Val(Textl.Text)End IfS = In
25、 dexEnd SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me Left = (Scree n. Width - Me.Width) / 2End SubPrivate Sub tui_Click()Forml.ShowMe.HideEnd SubPrivate Sub xin_Click()Textl.Text =End Sub编写结束窗体 form6 ( Form6 )中的代码:Opti on Explicit Dim x As In teger, Y As In teger, a As In te
26、ger, m As Long, N As Long Private Sub Form_Activate()Timerl.E nabled = TrueTimer3.E nabled = TrueTimer5.E nabled = TrueTimer7.E nabled = TrueTimer9.E nabled = TrueTimer11.E nabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Scree n.Height - Me.Height) / 2Me Left = (Scree n. Width - Me.Width) / 2Pi
27、cture1 = LoadPictureCCUsersLQRDesktopVB.qwe.jpg)Picture1.AutoRedraw = TruePicture1.Pai ntPicture Picture1.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyPicture2 = LoadPictureCCUsersLQRDesktopVB.qwe.jpg)Picture2.AutoRedraw = TruePicture2.Pai ntPicture Picture2.Picture, 0, 0, 2250, 2250, , , , , vbSrcCo
28、pyPicture3 = LoadPictureCCUsersLQRDesktopVB.qwe.jpg)Picture3.AutoRedraw = TruePicture3.Pai ntPicture Picture3.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer()If Picture1.Width + Picture1.Left = Me.ScaleWidth The nTimer2.E nabled = TrueTimer1.E nabled = FalseElsePicture1.Left = Picture1.Left + 50End IfEnd SubPrivate Sub Timer2_Timer()If Picture1.Left 6700 The nTimer4.E nabled = TrueTimer3.E nabled =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023年耐辐照石英玻璃项目风险评价报告
- 2023年道路照明项目安全风险评价报告
- 2023年刮墨刀项目安全风险评价报告
- 应急演练现场处置方案演练
- 小学生撒谎心理问题分析
- 内蒙古牙克石市2023-2024学年中考数学模拟预测题含解析
- 工程训练报告总结
- 幼儿园教师节班级主题活动方案
- 幼儿中班健康活动教案计划
- 小学阅读理解技巧课件
- 最全等边角钢参数表Excel
- 会议纪要会议手册word模板
- 调度自动化系统应急预案(共10页)
- 电表度数确认单(共2页)
- 工业硅技术安全操作规程
- 老爷爷赶鹅、
- 2022年初中信息技术考试操作题
- 爱心捐赠仪式上教育局领导的讲话5篇
- 污水处理厂工程项目的重点难点问题及应对措施(完整版)
- 二年级阅读训练-《动物王国开大会》
- 城市道路的维修养护 城市道路养护维修作业安全技术规程.doc
评论
0/150
提交评论