VB小程序制作.docx

上传人:rrsccc 文档编号:9919428 上传时间:2021-04-04 格式:DOCX 页数:18 大小:584.80KB
返回 下载 相关 举报
VB小程序制作.docx_第1页
第1页 / 共18页
VB小程序制作.docx_第2页
第2页 / 共18页
VB小程序制作.docx_第3页
第3页 / 共18页
VB小程序制作.docx_第4页
第4页 / 共18页
亲,该文档总共18页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《VB小程序制作.docx》由会员分享,可在线阅读,更多相关《VB小程序制作.docx(18页珍藏版)》请在三一文库上搜索。

1、VB程序设计8.1.1 实验目的1)掌握 VB 多重窗体程序的概念。2)掌握多重窗体程序的设计方法。3)复习各种控件的使用方法。8.1.2 实验内容采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。8.1.3 实验步骤实验步骤如下:1) 建立启动窗体界面与设置对象属性。选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组 Command1( 0) Command1 ( 5),并修改属性如图 8-1 左所示。系统默认窗体 Form1 为启动窗体。2) 添加窗体。选择“工程”菜单,打开“添加窗体”对话框。按“打开”按钮,添加3 个标准窗体Form2Form4 。添加标准模块。选择“工程”

2、菜单, 打开“添加模块”对话框。按“打开”按钮,添加1 个标准模块Module1 。图 8-1 程序界面设计3) 建立子窗体界面与设置对象属性。界面如图8-1 所示,设置属性如表所示。表 8-1Form1 属性设置对象属性属性值说明Form1NameForm1启动窗体CaptionForm1Command1( 0)CaptionWho are you?Command1( 1)CaptiongameCommand1( 2)CaptionwriteboardCommand1( 3)CaptioncalculatorCommand1( 4)CaptionbyebyePicture1autoredra

3、wfalseLabel1captionLets start a wonderfuljourney表 8-2Form2 属性设置对象属性属性值说明Form2NameForm2输入个人资料窗口CaptionForm2Label11CaptionnameLabel12CaptiongenderLabel13CaptionIs that a girl?Fream1CaptionhobbiescommandcaptionokeyCaptionOption1CaptionfemaleValueTrue默认被选中Option2CaptionmaleValueTrue默认被选中Check1CaptionWoW

4、Check2CaptionLeague of LegendsCheck3CaptionDungeon and FighterCheck4CaptionQQspeedCheck5CaptionfilmsCheck6Captionmovie表 8-3Form3 属性设置对象属性属性值说明Form3NameForm3CaptionForm3Command1CaptionhappinessCommand2CaptionbeginCommand3CaptionloveCommand4CaptionbeautyCommand5CaptionlaughLabel1captionscroesLabel2Cap

5、tion0Timer1interval500Timer2interval71表 8-4Form4 属性设置对象属性属性值说明Form4NameForm4CaptionForm4LabelcaptionLabel2Caption路漫漫其修远兮Label3Caption吾将上下而求索TextBoxtextPicture1pictureCaption返回表 8-5Form5 属性设置对象属性属性值说明FormNameForm5CaptionForm5Command1(09)caption19,0Command1(10)caption.Command2(04)caption+-*/=Label2Cap

6、tion路漫漫其修远兮Label3Caption吾将上下而求索TextBoxtext表 8-6Form6 属性设置对象属性属性值说明Form4NameForm6CaptionForm6Labelcaptionwelcome touse thissystem again !Label2Captionthank you !Picture1pictureTimer112interval1Timer13interval10004) 编写代码。编写“启动”窗体form1 ( Form1 )中代码:Option ExplicitDim i As Integer, ur1 As String, N As I

7、ntegerPrivate Sub Command1_Click(Index As Integer)N = IndexSelect Case NCase 0Form2.ShowMe.HideCase 1Form3.ShowMe.HideCase 2Form4.ShowMe.HideCase 3Form5.ShowMe.HideCase 5Form6.ShowMe.HideEnd SelectEnd SubPrivate Sub Form_Activate()Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Screen.H

8、eight - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture2 = LoadPicture(C:UsersLQRDesktopVB.1.gif)Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer()On Error GoTo Errur1 = C:UsersLQRDesktopVB. & i & .gifP

9、icture2.Picture = LoadPicture(ur1)i = i + 1Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopyExit SubErr:i = 1End Sub编写“输入个人资料”窗体form2 ( Form2 )中的代码:Private Sub Command1_Click()If Text1.Text = Thena = InputBox(You forget to input your name? , Attent

10、ion!, Your name! )If a = Or a = Your name ! Then Exit SubText1.Text = aElse: Form1.ShowForm2.HideEnd IfEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture1 = LoadPicture(C:UsersLQRDesktopVB.fei.jpg)Picture1.AutoRedraw = TruePicture1.Pa

11、intPicture Picture1.Picture, 0, 0, 3750, 4900, , , , , vbSrcCopy End Sub编写“ GAME ”窗体 form3 ( Form3)中的代码:Dim a As Integer, i As Integer, ur1 As StringPrivate Sub Command1_Click()If Command1.BackColor = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command2_Click()Timer1.

12、Enabled = TrueEnd SubPrivate Sub Command3_Click()If Command3.BackColor = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command4_Click()If Command4.BackColor = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command5_Click()If Command5.BackCol

13、or = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub cw_Click()Label2 = End SubPrivate Sub Timer2_Timer()On Error GoTo Err新建文件夹 . & i & .jpgPicture1.Picture = LoadPicture(ur1)i = i + 1Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , ,

14、 , , vbSrcCopy Exit SubErr:i = 45End SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2新建文件夹 .45.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer()Static x

15、 As Integera = Int(Rnd() * 4)Select Case aCase 0Command1.BackColor = RGB(225, 0, 0)Command3.BackColor = RGB(15, 0, 0)Command4.BackColor = 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)Comman

16、d5.BackColor = RGB(15, 0, 0)Case 2Command4.BackColor = RGB(225, 0, 0)Command1.BackColor = RGB(15, 0, 0)Command3.BackColor = RGB(15, 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 =

17、 RGB(15, 0, 0)End SelectIf x 50 Thenx = x + 1ElseTimer1.Enabled = FalseCommand5.BackColor = RGB(15, 0, 0)Command1.BackColor = RGB(15, 0, 0)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()MsgBox

18、 rules : & Chr(13) & Hit the different color.In the fixed time, more hits, more scores! , vbOKOnly, RuleEnd Sub编写“ writeboard ”窗体 form4 ( Form4)中的代码:Private Sub N_Click()Text1.Text = End SubPrivate Sub O_Click()CommonDialog1.Filter = 所有文件( *.* ) |*.*| 文本文件( *.TXT )|*.txtCommonDialog1.FilterIndex = 1

19、CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub S_Click()CommonDialog1.ShowSaveText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub T_Click()Form1.ShowMe.HideEnd SubPrivate Sub Text1_Change()Text1.Text = Text1.TextEnd SubPrivate Sub Y_Click()CommonDialog1.ShowColorText1.

20、ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Z_Click()CommonDialog1.Flags = 3 Or 256CommonDialog1.ShowFontWith Text1.FontName = CommonDialog1.FontName.FontSize = CommonDialog1.FontSize.FontStrikethru = CommonDialog1.FontStrikethru.FontBold = CommonDialog1.FontBold.FontItalic = CommonDialog1.Fon

21、tItalic.FontUnderline = CommonDialog1.FontUnderline.ForeColor = CommonDialog1.ColorEnd WithEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture1 = LoadPicture(C:UsersLQRDesktopVB.qu.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Pi

22、cture1.Picture, 0, 0, 1500, 2500, , , , , vbSrcCopy End Sub编写“ calculator ”窗体 form5 ( Form5 )中的代码:Dim v As BooleanDim S As IntegerDim x As DoubleDim Y As DoublePrivate Sub Command1_Click(Index As Integer)If Form5.Tag = T ThenIf Index = 10 ThenText1.Text = 0ElseText1.Text = Command1(Index).CaptionEnd

23、 IfForm5.Tag = ElseText1.Text = Text1.Text & Command1(Index).CaptionEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer)Form5.Tag = TIf v Thenx = 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 Then

24、Text1.Text = x / YElseMsgBox 傻了?不能以0 为除数啊! , vbOKOnly, 提示 Text1.Text = xv = FalseEnd IfCase 4Y = 0v = FalseEnd Selectx = Val(Text1.Text)End IfS = IndexEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2End SubPrivate Sub tui_Click()Form1.Show

25、Me.HideEnd SubPrivate Sub xin_Click()Text1.Text = End Sub编写结束窗体form6 (Form6 )中的代码:Option ExplicitDim x As Integer, Y As Integer, a As Integer, m As Long, N As LongPrivate Sub Form_Activate()Timer1.Enabled = TrueTimer3.Enabled = TrueTimer5.Enabled = TrueTimer7.Enabled = TrueTimer9.Enabled = TrueTimer

26、11.Enabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture1 = LoadPicture(C:UsersLQRDesktopVB.qwe.jpg)Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopy Picture2 = LoadPictur

27、e(C:UsersLQRDesktopVB.qwe.jpg) Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopy Picture3 = LoadPicture(C:UsersLQRDesktopVB.qwe.jpg) Picture3.AutoRedraw = TruePicture3.PaintPicture Picture3.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopy End SubPrivat

28、e 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 + 50E

29、nd IfEnd SubPrivate Sub Timer4_Timer()If Picture1.Top = Me.ScaleWidth ThenTimer6.Enabled = TrueTimer5.Enabled = FalseElsePicture2.Left = Picture2.Left + 50End IfEnd SubPrivate Sub Timer6_Timer()If Picture2.Left 6700 ThenTimer8.Enabled = TrueTimer7.Enabled = FalseElsePicture2.Top = Picture2.Top + 50E

30、nd IfEnd SubPrivate Sub Timer8_Timer()If Picture2.Top = Me.ScaleWidth ThenTimer10.Enabled = TrueTimer9.Enabled = FalseElsePicture3.Left = Picture3.Left + 50End IfEnd SubPrivate Sub Timer10_Timer()If Picture3.Left 6700 ThenTimer12.Enabled = TrueTimer11.Enabled = FalseElsePicture3.Top = Picture3.Top + 50End IfEnd SubPrivate Sub Timer12_Timer()If Picture3.Top 0 ThenTimer11.Enabled = TrueTimer12.Enabled = FalseElsePicture3.Top = Picture3.Top - 50End IfEnd SubPrivate Sub Timer13_Timer()If a 11 Thena = a + 1ElseEndEnd IfEnd Sub5) 运行窗体。启动程序后,屏幕出现启动窗体,单击按钮,显示相应窗体,可以执行相应的命令,如图 10-2 所示。图 10-2多重窗体程序

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1