VB小程序制作_第1页
VB小程序制作_第2页
VB小程序制作_第3页
VB小程序制作_第4页
VB小程序制作_第5页
已阅读5页,还剩12页未读, 继续免费阅读

下载本文档

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

文档简介

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

2、”对话框。按“打开”按钮,添加 1个标准模块 Modulel。Form4文j衽编5a图8-1程序界面设计3)建立子窗体界面与设置对象属性。界面如图8-1所示,设置属性如表所示。表8-1 Forml属性设置对象属性属性值说明FormlNameForm1启动窗体CaptionForm1Commandl (0)CaptionWho are you?Commandl (1)CaptiongameCommandl CaptionwriteboardCommand1 (3)CaptioncalculatorCommand1 (4)CaptionbyebyePicture1autoredrawfalseLa

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

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

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

6、bel3Caption吾将上卜而求索TextBoxtext表8-6 Form6属性设置对象属性属性值说明Form4NameForm6CaptionForm6Labelcaptionwelcome to use this system again !Label2Captionthank you !PicturelpictureTimer112interval1Timer13interval10004)编写代码。编写启动窗体 forml (Forml)中代码:Option ExplicitDim i As Integer, ur1 As String, N As IntegerPrivate Su

7、b 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()Timerl.Enabled = TrueEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Heigh

8、t) / 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 & .gifPicture2.Picture = Lo

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

10、f 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) / 2Picturel = LoadPicture(C:UsersLQRDesktopVB.fei.jpg) Picturel.AutoRedraw = TruePicturel.PaintPicture Pictur

11、el.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.Enabled = TrueEnd Sub

12、Private 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.BackColor = RGB(225, 0, 0) T

13、henLabel2 = 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 + 1Picturel.AutoRedraw = TruePicturel.PaintPicture Picturel.Picture, 0, 0, 12135, 8295, , , vbSrcCopyExit SubErr:i

14、 = 45End SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2新建文件夹.45.jpg)Picturel.AutoRedraw = TruePicturel.PaintPicture Picturel.Picture, 0, 0, 12135, 8295, , , vbSrcCopy End SubPrivate Sub Timer1_Timer()Static x As Integera = Int(Rnd() * 4)Sele

15、ct 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)Command5.BackColor = RGB(15, 0, 0)Case

16、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 = RGB(15, 0, 0)End SelectIf x 50 T

17、henx = x + 1ElseTimer1.Enabled = FalseCommand5.BackColor = RGB(15, 0, 0)Commandl.BackColor = RGB(15, 0, 0)Command3.BackColor = RGB(15, 0, 0)Command4.BackColor = RGB(15, 0, 0) x = 0 End If End SubPrivate Sub tui_Click() Forml.ShowMe.HideEnd SubPrivate Sub wf_Click()MsgBox rules : & Chr(13) & Hit the

18、different color.In the fixed time, 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 = 1 CommonDialog1.ShowOpen Text1.

19、Text = CommonDialog1.FileName End SubPrivate Sub S_Click()CommonDialog1.ShowSaveText1.Text = CommonDialog1.FileName End SubPrivate Sub T_Click()Form1.ShowMe.Hide End SubPrivate Sub Text1_Change()Text1.Text = Text1.Text End SubPrivate Sub Y_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog

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

21、CommonDialog1.FontUnderline.ForeColor = CommonDialog1.ColorEnd WithEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2Picturel = LoadPicture(C:UsersLQRDesktopVB.qu.jpg)Picturel.AutoRedraw = TruePicturel.PaintPicture Picturel.Picture, 0, 0, 15

22、00, 2500, , , vbSrcCopy End Sub编写calculator”窗体 form5 (Form5)中的代码:Dim v As BooleanDim S As IntegerDim x As DoubleDim 丫 As DoublePrivate Sub Command1_Click(Index As Integer)If Form5.Tag = T ThenIf Index = 10 ThenTextl.Text = 0ElseTextl.Text = Command1(Index).CaptionEnd IfForm5.Tag =ElseTextl.Text = Te

23、xtl.Text & Command1(Index).CaptionEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer)Form5.Tag = TIf v Thenx = Val(Textl.Text) v = Not v Else Y = Val(Textl.Text) Select Case S Case 0 Textl.Text = x + Y Case 1 Textl.Text = x - Y Case 2 Textl.Text = x * Y Case 3 If Y 0 Then Textl.Text = x / Y El

24、seMsgBox 傻了 ?不能以 0为除数啊! , vbOKOnly,提示 Textl.Text = x v = False End If Case 4 Y = 0 v = False End Select x = Val(Textl.Text) End If S = Index End SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2 End SubPrivate Sub tui_Click() Forml.Show Me.Hide

25、 End SubPrivate Sub xin_Click() Textl.Text = End Sub编写结束窗体form6 (Form6)中的代码: Option Explicit Dim x As Integer, Y As Integer, a As Integer, m As Long, N As LongPrivate Sub Form_Activate()Timerl.Enabled = TrueTimer3.Enabled = TrueTimer5.Enabled = TrueTimer7.Enabled = TrueTimer9.Enabled = TrueTimerll.E

26、nabled = 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, , , vbSrcCopyPicture2 = LoadPicture(C:Users

27、LQRDesktopVB.qwe.jpg)Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 2250, 2250, , , vbSrcCopyPicture3 = LoadPicture(C:UsersLQRDesktopVB.qwe.jpg)Picture3.AutoRedraw = TruePicture3.PaintPicture Picture3.Picture, 0, 0, 2250, 2250, , , , , vbSrcCopy End SubPrivate 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.

温馨提示

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

最新文档

评论

0/150

提交评论