VB小程序制作--精选文档_第1页
VB小程序制作--精选文档_第2页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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)CaptionbyebyePicture1autoredrawfalseLabel1captionLet'

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

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

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

6、而求索TextBoxtext表8-6Form6属性设置对象属性属性值说明Form4NameForm6CaptionForm6Labelcaptionwelcome to use this system again !Label2Captionthank you !Picture1pictureTimer112interval1Timer13interval10004) 编写代码。编写“启动”窗体form1(Form1)中代码:Option ExplicitDim i As Integer, ur1 As String, N As IntegerPrivate Sub Command1_Clic

7、k(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.Height - Me.Height) / 2Me.Left =

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

9、;.gif"Picture2.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

10、to input your name?", "Attention!", "Your name!")If a = "" Or a = "Your name!" Then Exit SubText1.Text = aElse: Form1.Show Form2.HideEnd IfEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picture

11、1 = LoadPicture("C:UsersLQRDesktopVB.fei.jpg")Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 3750, 4900, , , , , vbSrcCopyEnd Sub编写“GAME”窗体form3(Form3)中的代码:Dim a As Integer, i As Integer, ur1 As StringPrivate Sub Command1_Click()If Command1.BackColor = RGB(225, 0,

12、0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command2_Click()Timer1.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) ThenLabel

13、2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command5_Click()If Command5.BackColor = RGB(225, 0, 0) ThenLabel2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub cw_Click()Label2 = ""End SubPrivate Sub Timer2_Timer()On Error GoTo Errur1 = "C:UsersLQRDesktop新建文件夹." & i &

14、amp; ".jpg"Picture1.Picture = LoadPicture(ur1)i = i + 1Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopyExit SubErr:i = 45End SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Pictur

15、e1 = LoadPicture("C:UsersLQRDesktop新建文件夹.45.jpg")Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopyEnd SubPrivate Sub Timer1_Timer()Static x As Integera = Int(Rnd() * 4)Select Case aCase 0Command1.BackColor = RGB(225, 0, 0)Command3.BackCo

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

17、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 = RGB(15, 0, 0)End SelectIf x < 50 Then x = x + 1 Else Timer1.Enabled = False Command5.BackColor

18、 = RGB(15, 0, 0) Command1.BackColor = RGB(15, 0, 0) Command3.BackColor = RGB(15, 0, 0) Command4.BackColor = RGB(15, 0, 0) x = 0 End IfEnd SubPrivate Sub tui_Click()Form1.ShowMe.HideEnd SubPrivate Sub wf_Click()MsgBox "rules:" & Chr(13) & "Hit the different color.In the fixed t

19、ime, more hits, more scores!", vbOKOnly, "Rule"End Sub编写“writeboard”窗体form4(Form4)中的代码:Private Sub N_Click()Text1.Text = ""End SubPrivate Sub O_Click()CommonDialog1.Filter = "所有文件(*.*)|*.*|文本文件(*.TXT)|*.txt"CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpenText1.T

20、ext = 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.ForeColor = CommonDialog1.Col

21、orEnd 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.FontItalic .FontUnderline =

22、 CommonDialog1.FontUnderline .ForeColor = CommonDialog1.Color End 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 Picture1.Pi

23、cture, 0, 0, 1500, 2500, , , , , vbSrcCopyEnd 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 = "0"ElseText1.Text = Command1(Index).Ca

24、ptionEnd IfForm5.Tag = ""ElseText1.Text = Text1.Text & Command1(Index).CaptionEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer)Form5.Tag = "T"If v Thenx = Val(Text1.Text)v = Not vElseY = Val(Text1.Text)Select Case SCase 0Text1.Text = x + YCase 1Text1.Text = x - YCase

25、2Text1.Text = x * YCase 3If Y <> 0 ThenText1.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 = (Sc

26、reen.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 Long, N As LongPrivate Sub Form_Activate()Timer1.Enabled = TrueTimer3.Enable

27、d = 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 = LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture1.AutoRedraw = TruePicture1.

28、PaintPicture Picture1.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyPicture2 = LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyPicture3 = LoadPicture("C:UsersLQRDesktopVB.qwe.jpg")Picture

29、3.AutoRedraw = TruePicture3.PaintPicture Picture3.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopyEnd SubPrivate Sub Timer1_Timer()If Picture1.Width + Picture1.Left >= Me.ScaleWidth ThenTimer2.Enabled = TrueTimer1.Enabled = FalseElse Picture1.Left = Picture1.Left + 50End IfEnd SubPrivate Sub Timer2_T

30、imer()If Picture1.Left <= 0 ThenTimer1.Enabled = TrueTimer2.Enabled = FalseElse Picture1.Left = Picture1.Left - 50End IfEnd SubPrivate Sub Timer3_Timer()If Picture1.Top + Picture1.Height > 6700 ThenTimer4.Enabled = TrueTimer3.Enabled = FalseElse Picture1.Top = Picture1.Top + 50End IfEnd SubPri

31、vate Sub Timer4_Timer()If Picture1.Top < 0 ThenTimer3.Enabled = TrueTimer4.Enabled = FalseElse Picture1.Top = Picture1.Top - 50End IfEnd SubPrivate Sub Timer5_Timer()If Picture2.Width + Picture2.Left >= Me.ScaleWidth ThenTimer6.Enabled = TrueTimer5.Enabled = FalseElse Picture2.Left = Picture2.Left + 50End IfEnd SubPrivate Sub Timer6_Timer()If Picture2.Left <= 0 ThenTimer5.Enabled = TrueTimer6.Enabled = FalseElse Picture2.Left = Picture2.Left - 50End IfEnd SubPrivate Sub Timer7_Timer()If Picture2.Top + Pi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论