VB小程序制作_第1頁(yè)
VB小程序制作_第2頁(yè)
VB小程序制作_第3頁(yè)
VB小程序制作_第4頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、VB程序設(shè)計(jì)8.1.1 實(shí)驗(yàn)?zāi)康?)掌握 VB 多重窗體程序的概念。2)掌握多重窗體程序的設(shè)計(jì)方法。3)復(fù)習(xí)各種控件的使用方法。采用多窗體技術(shù)編寫程序,分別在不同的窗體上實(shí)現(xiàn)不同功能。8.1.3 實(shí)驗(yàn)步驟實(shí)驗(yàn)步驟如下:1) 建立啟動(dòng)窗體界面與設(shè)置對(duì)象屬性。選擇“新建”工程,進(jìn)入窗體設(shè)計(jì)器,在窗體中添加命令按鈕組 Command1 ( 0)Command1 ( 5),并修改屬性如圖8-1 左所示。系統(tǒng)默認(rèn)窗體Form1 為啟動(dòng)窗體。2) 添加窗體。選擇“工程”菜單,打開“添加窗體”對(duì)話框。按“打開”按鈕,添加3 個(gè)標(biāo)準(zhǔn)窗體Form2Form4 。添加標(biāo)準(zhǔn)模塊。選擇“工程”菜單,打開“添加模塊”對(duì)

2、話框。按“打開”按鈕,添加 1 個(gè)標(biāo)準(zhǔn)模塊 Module1 。圖 8-1 程序界面設(shè)計(jì)3) 建立子窗體界面與設(shè)置對(duì)象屬性。界面如圖8-1 所示,設(shè)置屬性如表所示。表 8-1Form1 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明Form1NameForm1啟動(dòng)窗體CaptionForm1Command1 (0)CaptionWho are you?Command1 (1)CaptiongameCommand1 (2)CaptionwriteboardCommand1 (3)CaptioncalculatorCommand1 (4)CaptionbyebyePicture1autoredrawfalseLabel

3、1captionLet's start awonderfuljourney表 8-2Form2 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明Form2NameForm2輸入個(gè)人資料窗口CaptionForm2Label11CaptionnameLabel12CaptiongenderLabel13CaptionIs that a girl?Fream1CaptionhobbiescommandcaptionokeyCaptionOption1CaptionfemaleValueTrue默認(rèn)被選中Option2CaptionmaleValueTrue默認(rèn)被選中Check1CaptionWoWCheck2C

4、aptionLeague of LegendsCheck3CaptionDungeon and FighterCheck4CaptionQQspeedCheck5CaptionfilmsCheck6Captionmovie表 8-3Form3 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明Form3NameForm3CaptionForm3Command1CaptionhappinessCommand2CaptionbeginCommand3CaptionloveCommand4CaptionbeautyCommand5CaptionlaughLabel1captionscroesLabel2Caption0Ti

5、mer1interval500Timer2interval71表 8-4Form4 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明Form4NameForm4CaptionForm4LabelcaptionLabel2Caption路漫漫其修遠(yuǎn)兮Label3Caption吾將上下而求索TextBoxtextPicture1pictureCaption返回表 8-5Form5 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明FormNameForm5CaptionForm5Command1(09)caption19,0Command1(10)caption.Command2(04)caption+-*/=Label2Caption路漫漫

6、其修遠(yuǎn)兮Label3Caption吾將上下而求索TextBoxtext表 8-6Form6 屬性設(shè)置對(duì)象屬性屬性值說(shuō)明Form4NameForm6CaptionForm6Labelcaptionwelcome to use thissystem again !Label2Captionthank you !Picture1pictureTimer112interval1Timer13interval10004) 編寫代碼。編寫“啟動(dòng)”窗體form1 ( Form1 )中代碼:Option ExplicitDim i As Integer, ur1 As String, N As Integer

7、Private 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.Height

8、- 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.

9、" & i & ".gif"Picture2.Picture = LoadPicture(ur1)i = i + 1Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopy Exit SubErr:i = 1End Sub編寫“輸入個(gè)人資料”窗體form2 ( Form2 )中的代碼:Private Sub Command1_Click()If Text1.Text = "" Then

10、a = InputBox("You forget to input your name? ", "Attention!", "Your nameIf a = "" Or a = "Your name! " Then Exit Sub! ")Text1.Text = aElse: Form1.ShowForm2.HideEnd IfEnd SubPrivate Sub Form_Load()Me.Top = (Screen.Height - Me.Height) / 2Me.Left = (Scr

11、een.Width - Me.Width) / 2Picture1 = 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, ur1 As StringPrivate Sub Command1_Click

12、()If Command1.BackColor = RGB(225, 0, 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 Command

13、4.BackColor = RGB(225, 0, 0) ThenLabel2 = 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 Err新建文件夾 ."

14、 & i & ".jpg"Picture1.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.Width

15、) / 2新建文件夾 .45.jpg")Picture1.AutoRedraw = TruePicture1.PaintPicture Picture1.Picture, 0, 0, 12135, 8295, , , , , vbSrcCopy End SubPrivate Sub Timer1_Timer()Static x As Integera = Int(Rnd() * 4)Select Case aCase 0Command1.BackColor = RGB(225, 0, 0)Command3.BackColor = RGB(15, 0, 0)Command4.BackC

16、olor = 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(15,

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

18、 = 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 "rules : " & Chr(13) & "Hit the different color.In the fixed time, more hits, more scoresvbOKOnly,

19、"Rule"End Subwriteboard ”窗體 form4 ( Form4 )中的代碼:Private Sub N_Click()Text1.Text = ""End SubCommonDialog1.Filter = "所有文件(*.* ) |*.*| 文本文件(*.TXT ) |*.txt"CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpen! ",Text1.Text = CommonDialog1.FileNameEnd SubPrivate Sub S_Cl

20、ick()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.ColorEnd SubPrivate Sub Z_Click()CommonDialog1.Flags =

21、 3 Or 256CommonDialog1.ShowFontWith Text1.FontName = CommonDialog1.FontName.FontSize = CommonDialog1.FontSize.FontStrikethru = CommonDialog1.FontStrikethru.FontBold = CommonDialog1.FontBold.FontItalic = CommonDialog1.FontItalic.FontUnderline = CommonDialog1.FontUnderline.ForeColor = CommonDialog1.Co

22、lorEnd 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.Picture, 0, 0, 1500, 2500, , , , , vbSrcCopy End Sub編寫“ calcu

23、lator ”窗體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).CaptionEnd IfForm5.Tag = ""ElseText1.Text = T

24、ext1.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 2Text1.Text = x * YCase 3If Y <> 0 ThenText1.Te

25、xt = x / YElseMsgBox " 傻了?不能以0 為除數(shù)啊!", 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_C

26、lick()Form1.ShowMe.HideEnd SubPrivate Sub xin_Click()Text1.Text = ""End Sub編寫結(jié)束窗體form6 ( Form6 )中的代碼:Option ExplicitDim x As Integer, Y As Integer, a As Integer, m As Long, N As Long Private Sub Form_Activate()Timer1.Enabled = TrueTimer3.Enabled = TrueTimer5.Enabled = TrueTimer7.Enabled =

27、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.PaintPicture Picture1.Picture, 0, 0, 2250, 225

28、0, , , , , vbSrcCopy Picture2 = LoadPicture("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 P

29、icture3.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 <= 0 ThenTimer1.

30、Enabled = TrueTimer2.Enabled = FalseElsePicture1.Left = Picture1.Left - 50End IfEnd SubPrivate Sub Timer3_Timer()If Picture1.Top + Picture1.Height > 6700 ThenTimer4.Enabled = TrueTimer3.Enabled = FalseElsePicture1.Top = Picture1.Top + 50End IfEnd SubPrivate Sub Timer4_Timer()If Picture1.Top <

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

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論