VB小程序制作.docx

上传人:b****5 文档编号:6738879 上传时间:2023-01-09 格式:DOCX 页数:22 大小:4.54MB
下载 相关 举报
VB小程序制作.docx_第1页
第1页 / 共22页
VB小程序制作.docx_第2页
第2页 / 共22页
VB小程序制作.docx_第3页
第3页 / 共22页
VB小程序制作.docx_第4页
第4页 / 共22页
VB小程序制作.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

VB小程序制作.docx

《VB小程序制作.docx》由会员分享,可在线阅读,更多相关《VB小程序制作.docx(22页珍藏版)》请在冰豆网上搜索。

VB小程序制作.docx

VB小程序制作

VB程序设计

实验目的

1)掌握VB多重窗体程序的概念。

2)掌握多重窗体程序的设计方法。

3)复习各种控件的使用方法。

实验内容

采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。

实验步骤

实验步骤如下:

1)建立启动窗体界面与设置对象属性。

选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组Command1(0)~Command1(5),并修改属性如图8-1左所示。

系统默认窗体Form1为启动窗体。

2)添加窗体。

选择“工程”菜单,打开“添加窗体”对话框。

按“打开”按钮,添加3个标准窗体Form2~Form4。

添加标准模块。

选择“工程”菜单,打开“添加模块”对话框。

按“打开”按钮,添加1个标准模块Module1。

图8-1程序界面设计

3)建立子窗体界面与设置对象属性。

界面如图8-1所示,设置属性如表所示。

表8-1Form1属性设置

对象

属性

属性值

说明

Form1

Name

Form1

启动窗体

Caption

Form1

Command1(0)

Caption

Whoareyou?

Command1

(1)

Caption

game

Command1

(2)

Caption

writeboard

Command1(3)

Caption

calculator

Command1(4)

Caption

byebye

Picture1

autoredraw

false

Label1

caption

Let'sstartawonderfuljourney

表8-2Form2属性设置

对象

属性

属性值

说明

Form2

Name

Form2

输入个人资料窗口

Caption

Form2

Label11

Caption

name

Label12

Caption

gender

Label13

Caption

Isthatagirl?

Fream1

Caption

hobbies

command

caption

okey

Caption

Option1

Caption

female

Value

True

默认被选中

Option2

Caption

male

Value

True

默认被选中

Check1

Caption

WoW

Check2

Caption

LeagueofLegends

Check3

Caption

DungeonandFighter

Check4

Caption

QQspeed

Check5

Caption

films

Check6

Caption

movie

表8-3Form3属性设置

对象

属性

属性值

说明

Form3

Name

Form3

Caption

Form3

Command1

Caption

happiness

Command2

Caption

begin

Command3

Caption

love

Command4

Caption

beauty

Command5

Caption

laugh

Label1

caption

scroes

Label2

Caption

0

Timer1

interval

500

Timer2

interval

71

表8-4Form4属性设置

对象

属性

属性值

说明

Form4

Name

Form4

Caption

Form4

Label

caption

Label2

Caption

路漫漫其修远兮

Label3

Caption

吾将上下而求索

TextBox

text

Picture1

picture

Caption

返回

表8-5Form5属性设置

对象

属性

属性值

说明

Form

Name

Form5

Caption

Form5

Command1(0~9)

caption

1~9,0

Command1(10)

caption

.

Command2(0~4)

caption

+-*/=

Label2

Caption

路漫漫其修远兮

Label3

Caption

吾将上下而求索

TextBox

text

表8-6Form6属性设置

对象

属性

属性值

说明

Form4

Name

Form6

Caption

Form6

Label

caption

welcometousethissystemagain!

!

Label2

Caption

thankyou!

Picture1

picture

Timer1~12

interval

1

Timer13

interval

1000

4)编写代码。

编写“启动”窗体form1(Form1)中代码:

OptionExplicit

DimiAsInteger,ur1AsString,NAsInteger

PrivateSubCommand1_Click(IndexAsInteger)

N=Index

SelectCaseN

Case0

 

Case1

 

Case2

 

Case3

 

Case5

 

EndSelect

EndSub

PrivateSubForm_Activate()

=True

EndSub

PrivateSubForm_Load()

=-/2

=-/2

Picture2=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,3000,3000,,,,,vbSrcCopy

EndSub

 

PrivateSubTimer1_Timer()

OnErrorGoToErr

ur1="C:

\Users\LQR\Desktop\VB.\"&i&".gif"

=LoadPicture(ur1)

i=i+1

=True

0,0,3000,3000,,,,,vbSrcCopy

ExitSub

Err:

i=1

EndSub

 

编写“输入个人资料”窗体form2(Form2)中的代码:

PrivateSubCommand1_Click()

If=""Then

a=InputBox("Youforgettoinputyourname?

","Attention!

","Yourname!

")

Ifa=""Ora="Yourname!

"ThenExitSub

=a

Else:

EndIf

EndSub

PrivateSubForm_Load()

=-/2

=-/2

Picture1=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,3750,4900,,,,,vbSrcCopy

EndSub

编写“GAME”窗体form3(Form3)中的代码:

DimaAsInteger,iAsInteger,ur1AsString

PrivateSubCommand1_Click()

If=RGB(225,0,0)Then

Label2=Val+1

EndIf

EndSub

PrivateSubCommand2_Click()

=True

EndSub

PrivateSubCommand3_Click()

If=RGB(225,0,0)Then

Label2=Val+1

EndIf

EndSub

PrivateSubCommand4_Click()

If=RGB(225,0,0)Then

Label2=Val+1

EndIf

EndSub

PrivateSubCommand5_Click()

If=RGB(225,0,0)Then

Label2=Val+1

EndIf

EndSub

 

PrivateSubcw_Click()

Label2=""

EndSub

PrivateSubTimer2_Timer()

OnErrorGoToErr

ur1="C:

\Users\LQR\Desktop\新建文件夹.\"&i&".jpg"

=LoadPicture(ur1)

i=i+1

=True

0,0,12135,8295,,,,,vbSrcCopy

ExitSub

Err:

i=45

EndSub

PrivateSubForm_Load()

=-/2

=-/2

Picture1=LoadPicture("C:

\Users\LQR\Desktop\新建文件夹.\")

=True

0,0,12135,8295,,,,,vbSrcCopy

EndSub

PrivateSubTimer1_Timer()

StaticxAsInteger

a=Int(Rnd()*4)

SelectCasea

Case0

=RGB(225,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

Case1

=RGB(225,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

Case2

=RGB(225,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

Case3

=RGB(225,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

EndSelect

Ifx<50Then

x=x+1

Else

=False

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

=RGB(15,0,0)

x=0

EndIf

EndSub

PrivateSubtui_Click()

 

EndSub

PrivateSubwf_Click()

MsgBox"rules:

"&Chr(13)&"Hitthedifferentthefixedtime,morehits,morescores!

",vbOKOnly,"Rule"

EndSub

编写“writeboard”窗体form4(Form4)中的代码:

PrivateSubN_Click()

=""

EndSub

PrivateSubO_Click()

="所有文件(*.*)|*.*|文本文件(*.TXT)|*.txt"

=1

=

EndSub

PrivateSubS_Click()

=

EndSub

PrivateSubT_Click()

 

EndSub

PrivateSubText1_Change()

=

EndSub

PrivateSubY_Click()

=

EndSub

PrivateSubZ_Click()

=3Or256

WithText1

.FontName=

.FontSize=

.FontStrikethru=

.FontBold=

.FontItalic=

.FontUnderline=

.ForeColor=

EndWith

EndSub

PrivateSubForm_Load()

=-/2

=-/2

Picture1=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,1500,2500,,,,,vbSrcCopy

EndSub

编写“calculator”窗体form5(Form5)中的代码:

DimvAsBoolean

DimSAsInteger

DimxAsDouble

DimYAsDouble

PrivateSubCommand1_Click(IndexAsInteger)

If="T"Then

IfIndex=10Then

="0"

Else

=Command1(Index).Caption

EndIf

=""

Else

=&Command1(Index).Caption

EndIf

EndSub

PrivateSubCommand2_Click(IndexAsInteger)

="T"

IfvThen

x=Val

v=Notv

Else

Y=Val

SelectCaseS

Case0

=x+Y

Case1

=x-Y

Case2

=x*Y

Case3

IfY<>0Then

=x/Y

Else

MsgBox"傻了?

不能以0为除数啊!

",vbOKOnly,"提示"

=x

v=False

EndIf

Case4

Y=0

v=False

EndSelect

x=Val

EndIf

S=Index

EndSub

PrivateSubForm_Load()

=-/2

=-/2

EndSub

PrivateSubtui_Click()

 

EndSub

PrivateSubxin_Click()

=""

EndSub

编写结束窗体form6(Form6)中的代码:

OptionExplicit

DimxAsInteger,YAsInteger,aAsInteger,mAsLong,NAsLong

 

PrivateSubForm_Activate()

=True

=True

=True

=True

=True

=True

EndSub

PrivateSubForm_Load()

=-/2

=-/2

Picture1=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,2250,2250,,,,,vbSrcCopy

Picture2=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,2250,2250,,,,,vbSrcCopy

Picture3=LoadPicture("C:

\Users\LQR\Desktop\VB.\")

=True

0,0,2250,2250,,,,,vbSrcCopy

EndSub

 

PrivateSubTimer1_Timer()

If+>=Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer2_Timer()

If<=0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer3_Timer()

If+>6700Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer4_Timer()

If<0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer5_Timer()

If+>=Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer6_Timer()

If<=0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer7_Timer()

If+>6700Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer8_Timer()

If<0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer9_Timer()

If+>=Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer10_Timer()

If<=0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer11_Timer()

If+>6700Then

=True

=False

Else

=+50

EndIf

EndSub

PrivateSubTimer12_Timer()

If<0Then

=True

=False

Else

=-50

EndIf

EndSub

PrivateSubTimer13_Timer()

Ifa<11Then

a=a+1

Else

End

EndIf

EndSub

5)运行窗体。

启动程序后,屏幕出现启动窗体,单击按钮,显示相应窗体,可以执行相应的命令,如图10-2所示。

图10-2多重窗体程序

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1