VB小程序制作_第1頁(yè)
VB小程序制作_第2頁(yè)
VB小程序制作_第3頁(yè)
VB小程序制作_第4頁(yè)
VB小程序制作_第5頁(yè)
已閱讀5頁(yè),還剩7頁(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、【精品文檔】如有侵權(quán),請(qǐng)聯(lián)系網(wǎng)站刪除,僅供學(xué)習(xí)與交流VB小程序制作.精品文檔.VB程序設(shè)計(jì)8.1.1 實(shí)驗(yàn)?zāi)康?)掌握VB多重窗體程序的概念。2)掌握多重窗體程序的設(shè)計(jì)方法。3)復(fù)習(xí)各種控件的使用方法。8.1.2實(shí)驗(yàn)內(nèi)容采用多窗體技術(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) 添加窗體。選擇“工程”菜單,打開(kāi)“添加窗體”對(duì)話框。按“打開(kāi)”按鈕,添加3個(gè)標(biāo)準(zhǔn)窗

2、體Form2Form4。添加標(biāo)準(zhǔn)模塊。選擇“工程”菜單,打開(kāi)“添加模塊”對(duì)話框。按“打開(kāi)”按鈕,添加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)CaptionbyebyePictu

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

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

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

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

7、 N As IntegerPrivate 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 = (S

8、creen.Height - Me.Height) / 2Me.Left = (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:UsersL

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

10、ot; Thena = InputBox("You forget 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

11、= (Screen.Width - Me.Width) / 2Picture1 = 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

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 Errur1 = "C

14、:UsersLQRDesktop新建文件夾." & i & ".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

15、 = (Screen.Width - Me.Width) / 2Picture1 = 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.Bac

16、kColor = 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 2Command4.BackColor = RGB(2

17、25, 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 Then x = x + 1 Else Tim

18、er1.Enabled = False Command5.BackColor = 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) & "

19、Hit the 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.Filter

20、Index = 1CommonDialog1.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.ShowCo

21、lorText1.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 = Com

22、monDialog1.FontItalic .FontUnderline = 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 =

23、 TruePicture1.PaintPicture Picture1.Picture, 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&qu

24、ot;ElseText1.Text = Command1(Index).CaptionEnd 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.Tex

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

26、n.Height - Me.Height) / 2Me.Left = (Screen.Width - Me.Width) / 2End SubPrivate Sub tui_Click()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 LongPrivate Sub Form_Activa

27、te()Timer1.Enabled = TrueTimer3.Enabled = 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&quo

28、t;)Picture1.AutoRedraw = TruePicture1.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:U

29、sersLQRDesktopVB.qwe.jpg")Picture3.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

30、 + 50End IfEnd SubPrivate Sub Timer2_Timer()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.T

31、op = Picture1.Top + 50End IfEnd SubPrivate 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

溫馨提示

  • 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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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)論