VB小程序制作_第1頁
VB小程序制作_第2頁
VB小程序制作_第3頁
VB小程序制作_第4頁
VB小程序制作_第5頁
免費預(yù)覽已結(jié)束,剩余19頁可下載查看

下載本文檔

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

文檔簡介

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

2、鈕,添加 窗體Form2Form4。添加標(biāo)準(zhǔn)模塊。選擇“工程”菜單,打開“添加模塊”對話框。 個標(biāo)準(zhǔn)模塊1按“打開”按鈕,添加.Form51234口567 890+*/ruForme喻 sysfcTzi again! ,.圖8-1程序界面設(shè)計3) 建立子窗體界面與設(shè)置對象屬性。界面如圖8-1所示,設(shè)置屬性如表所示。表8-1Formi屬性設(shè)置對象屬性屬性值說明FormiNameForm1啟動窗體Cap ti onForm10)( Command1Cap ti onWho are you?1) Command1 (Cap ti ongame)Command1 ( 2Cap ti onwritebo

3、ard)3Command1 (Cap ti oncalculator4)( Command1Cap ti onbyebyePicture1autoredrawfalseLabel1cap tionLets start a won derful jour ney表8-2Form2屬性設(shè)置對象屬性屬性值說明Form2NameForm2輸入個人資料窗口Cap ti onForm2LabelllCap ti onn ameLabel12Cap ti ongenderLabel13Cap ti onIs that a girl?FreamiCap ti onhobbiescomma ndcap ti o

4、nokeyCap ti onOp tio n1Cap ti onfemaleValueTrue默認(rèn)被選中Op tio n2Cap ti onmaleValueTrue默認(rèn)被選中Check1Cap ti onWoWCheck2Cap ti onLeague of Lege ndsCheck3Cap ti onDungeon and FighterCheck4Cap ti onQQs peedCheck5Cap ti onfilmsCheck6Cap ti onmovie表8-3Form3屬性設(shè)置對象屬性屬性值說明Form3NameForm3Cap ti onForm3Comma nd1Cap t

5、i onhappin essComma nd2Cap ti onbeginComma nd3Cap ti onloveComma nd4Cap ti onbeautyComma nd5Cap ti onlaughLabel1cap tionscroesLabel2Cap ti on0Timer1in terval500Timer2in terval71Form4屬性設(shè)置表8-4對象屬性屬性值說明Form4NameForm4Cap ti onForm4Labelcap tionLabel2Cap ti on路漫漫其修遠(yuǎn)兮Label3Cap ti on吾將上下而求索TextBoxtextPictu

6、re1pictureCap ti on返回8-5表Form5屬性設(shè)置對象屬性屬性值說明FormNameForm5Cap ti onForm5Comma nd1(09)cap ti on19,0Comma nd1(10)cap ti onComma nd2(04)cap tion+ -*/=Label2Cap ti on路漫漫其修遠(yuǎn)兮Label3Cap ti on吾將上下而求索TextBoxtext屬性設(shè)置表8-6Form6對象屬性屬性值說明Form4NameForm6Cap ti onForm6Labelcap ti onwelcome to use this system aga in !L

7、abel2Cap ti onthankyou !Picture1pictureTimer112in terval1Timer13in terval10004) 編寫代碼。編寫啟動”窗體 form1 ( Form1 )中代碼:Op ti on Exp licitDim i As In teger, ur1 As Stri ng, N As In tegerPrivate Sub Comma nd1_Click( In dex As In teger)N = IndexSelect Case NCase 0Form2.ShowMe.HideCase 1Form3.ShowMe.HideCase 2

8、Form4.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 = (Screen.Width - Me.Width) / 2Picture2 = LoadPicture(C:UsersLQRDesktopVB.1.gif)Picture2.AutoR

9、edraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , , , vbSrcCopyEnd SubPrivate Sub Timer1_Timer()On Error GoTo Err ur1 = C:UsersLQRDesktopVB. & i & .gifPicture2.Picture = LoadPicture(ur1)Picture2.AutoRedraw = TruePicture2.PaintPicture Picture2.Picture, 0, 0, 3000, 3000, , , ,

10、, vbSrcCopyExit SubErr:End Sub編寫“輸入個人資料”窗體 form2 ( Form2 )中的代碼:Private Sub Command1_Click()If Text1.Text = Then! Then Exit Suba = InputBox(You forget to input your name ? , Attention!, Your name ! ) If a = Or a = Your nameText1.Text = aElse: Form1.ShowForm2.HideEnd IfEnd SubPrivate Sub Form_Load()-

11、Me.Height) / 2- Me.Width) / 2Me.Top = (Screen.HeightMe.Left = (Screen.WidthPicture1 = 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,

12、ur1 As StringPrivate Sub Command1_Click()If Command1.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command2_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Command3_Click()If Command3.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd

13、SubPrivate Sub Command4_Click()If Command4.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub Command5_Click()If Command5.BackColor = RGB(225, 0, 0) Then Label2 = Val(Label2.Caption) + 1End IfEnd SubPrivate Sub cw_Click()Label2 = End SubPrivate Sub Timer2_Timer(

14、)On Error GoTo Err新建文件夾 . & i & .jpgPicture1.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

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

16、kColor = 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(1

17、5, 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 ThenElseTimer1.Enabled = FalseCommand5.BackColor = RGB(15, 0, 0)Command1.BackColor = RGB(15, 0, 0

18、) 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()MsgBoxules: & Chr(13) & Hit the different color.In the fixed time, more hits, more scores! , vbOKOnly, RuleEnd Sub編寫“ writeboard ”窗體 form4 (

19、Form4 )中的代碼:Private Sub N_Click()Text1.Text = End SubPrivate Sub O_Click()潃浭湯楄污杯 ?楆瑬牥 ?尠所有文件( *.* ) |*.*| 文本文件( *.TXT )|*.txt CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpenText1.Text = CommonDialog1.FileNameEnd SubPrivate Sub S_Click()CommonDialog1.ShowSaveText1.Text = CommonDialog1.FileNameEnd

20、 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 = 3 Or 256 CommonDialog1.ShowFont With Text1.FontName = CommonDial

21、og1.FontName.FontSize = CommonDialog1.FontSize .FontStrikethru = CommonDialog1.FontStrikethru .FontBold = CommonDialog1.FontBold .FontItalic = CommonDialog1.FontItalic .FontUnderline = CommonDialog1.FontUnderline .ForeColor = CommonDialog1.ColorEnd WithEnd SubPrivate Sub Form_Load()Me.Top = (Screen.

22、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, , , , , vbSrcCopyEnd Sub編寫“ calculator ”窗體 form5 ( Form5 )中的代碼:Dim v As BooleanDim S As IntegerDim x As

23、DoubleDim Y As DoublePrivate Sub Command1_Click(Index As Integer)If Form5.Tag = T ThenIf Index = 10 ThenText1.Text =ElseText1.Text = Command1(Index).CaptionEnd IfForm5.Tag = ElseText1.Text = Text1.Text & Command1(Index).CaptionEnd IfEnd SubPrivate Sub Command2_Click(Index As Integer)Form5.Tag = TIf

24、v Then x = 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.Text = x / YElse獍?硯尠傻了?不能以 0 為除數(shù)?。??瘠佢佋汮 ?尠提示Text1.Text = x v = FalseEnd IfCase 4 x = Val(Text1.Text)v = FalseEnd SelectEnd IfS = Ind

25、exEnd SubPrivate Sub Form_Load()Me.Top = (Screen.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

26、 Long, N As LongPrivate Sub Form_Activate()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 = LoadPictur

27、e(C:UsersLQRDesktopVB.qwe.jpg)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 = LoadPi

28、cture(C:UsersLQRDesktopVB.qwe.jpg)Picture3.AutoRedraw = TruePrivate 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 + 50End IfEnd Su

溫馨提示

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

評論

0/150

提交評論