arrow2=1
Else
Label1.Top=Label1.Top-50
EndIf
Else
IfLabel1.Top+Label1.Height>Form1.ScaleTop+Form1.ScaleHeightThen
arrow2=0
Else
Label1.Top=Label1.Top+50
EndIf
EndIf
EndSub
实验4:
高级控件的应用
实验目的:
掌握imagelist,treeview,listview的用法
实验要求:
实现右图效果,并可以在右边图标框内可以通过弹出菜单实现图标的排列。
下面状态栏根据不同的选择给出相应的提示
实验步骤:
(1):
添加imagelist,treeview,listview控件并进行相应的属性设置
(2):
参考事件代码
OptionExplicit
PrivateSubbpl_Click()
ListView1.Arrange=lvwNone
EndSub
PrivateSubdddq_Click()
ListView1.Arrange=lvwAutoTop
EndSub
PrivateSubForm_Resize()
ListView1.Left=Form1.ScaleLeft+TreeView1.Width+Label1.Width
IfForm1.Width-TreeView1.Width-Label1.Width*2>0Then
ListView1.Width=Form1.Width-TreeView1.Width-Label1.Width*2
EndIf
IfForm1.Height-StatusBar1.Height*2>0Then
ListView1.Height=Form1.Height-StatusBar1.Height*2
TreeView1.Height=ListView1.Height
Label1.Height=ListView1.Height
EndIf
EndSub
PrivateSubForm_Load()
DimmynodAsNode
Setmynod=TreeView1.Nodes.Add(,,"sports","体育")
Setmynod=TreeView1.Nodes.Add("sports",tvwChild,"ball","球类")
Setmynod=TreeView1.Nodes.Add("ball",tvwChild,"basketball","篮球")
Setmynod=TreeView1.Nodes.Add("ball",tvwChild,"football","足球")
Setmynod=TreeView1.Nodes.Add("ball",tvwChild,"pingpang","乒乓球")
Setmynod=TreeView1.Nodes.Add("ball",tvwChild,"shuttlecock","羽毛球")
Setmynod=TreeView1.Nodes.Add("sports",tvwChild,"swim","游泳")
Setmynod=TreeView1.Nodes.Add("swim",tvwChild,"free","自由泳")
Setmynod=TreeView1.Nodes.Add("swim",tvwChild,"butterfly","蝶泳")
Setmynod=TreeView1.Nodes.Add("swim",tvwChild,"backstroke","仰泳")
EndSub
PrivateSubLabel1_MouseUp(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
Label1.Left=Label1.Left+x
TreeView1.Width=TreeView1.Width+x
ListView1.Left=ListView1.Left+x
ListView1.Width=ListView1.Width-x
EndSub
PrivateSubListView1_MouseUp(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
IfButton=2Then
PopupMenupaixu
EndIf
EndSub
PrivateSubTreeView1_NodeClick(ByValNodeAsMSComctlLib.Node)
SelectCaseNode.Key
Case"ball"
ListView1.ListItems.Clear
StatusBar1.SimpleText="中国球类项目全面腾飞"
ListView1.ListItems.Add,"basketball","篮球",1
ListView1.ListItems.Add,"football","足球",2
ListView1.ListItems.Add,"pingpang","乒乓球",3
ListView1.ListItems.Add,"shuttlecock","羽毛球",4
Case"swim"
ListView1.ListItems.Clear
StatusBar1.SimpleText="中国游泳全面突破历史"
ListView1.ListItems.Add,"free","自由泳",5
ListView1.ListItems.Add,"butterfly","蝶泳",6
ListView1.ListItems.Add,"backstroke","蝶泳",7
EndSelect
ListView1.Arrange=lvwAutoTop
EndSub
PrivateSubzbdq_Click()
ListView1.Arrange=lvwAutoLeft
EndSub
实验5:
简单计算机绘图程序
实验目的:
了解VB中绘图的基本方法
实验要求:
用“更新数组”按钮产生一随机数组(0-100),然后用“绘图”按钮实现其柱形图的表示,用“排序”按钮实现由小到大排序,且可再用“绘图”按钮绘制新的柱形图,结果如图所示。
实验步骤:
(1):
添加控件,并设置相应属性。
(2):
编写代码:
OptionExplicit
DimiAsInteger
Dimshuzu(10)AsInteger
PrivateSubCommand1_Click()
DimkAsDouble
Picture1.Scale(0,110)-(100,0)
Picture1.Cls
Fori=0To90Step10
Label1(i/10).Top=shuzu(i/10)+5
Label1(i/10).BackStyle=0
Label1(i/10).AutoSize=True
Label1(i/10).Left=Picture1.ScaleLeft+i+1
Label1(i/10).Caption=shuzu(i/10)
Picture1.Line(i,0)-(i,shuzu(i/10)),QBColor(i/10)
Fork=0To5Step0.2
Picture1.Line(i+k,0)-(i+k,shuzu(i/10)),QBColor(i/10)
Nextk
Nexti
EndSub
PrivateSubCommand2_Click()
DimiAsInteger
DimkAsInteger
DimxAsInteger
Fori=0To8
Fork=iTo9
Ifshuzu(i)>shuzu(k)Then
x=shuzu(i)
shuzu(i)=shuzu(k)
shuzu(k)=x
EndIf
Nextk
Nexti
EndSub
PrivateSubCommand3_Click()
End
EndSub
PrivateSubCommand4_Click()
Fori=0To9
shuzu(i)=Int(Rnd*100)
Nexti
EndSub
实验6:
简单的记事本程序
实验目的:
通过记事本程序的实现掌握多种控件的综合运用,以及使用FSO进行文件的操作
实验要求:
基本等同于WINDOWS中的记事本程序,
实验步骤:
(1):
控件的添加及相应属性的设置,注意:
由于用到FSO对象,所以必须引用:
MicrosofeScriptingRuntime
(2):
代码实现
OptionExplicit
Dimcheck1AsBoolean,check2AsBoolean,check3AsBoolean
DimmyfilenameAsString,my1AsString
PrivateSubCombo1_Click()
Text1.FontSize=Combo1.ListIndex
EndSub
PrivateSubCommand1_Click()
UnloadMe
EndSub
PrivateSubbianji1_Click()
Text1.SelStart=0
Text1.SelLength=Len(Text1.Text)
bianji2.Enabled=True
bianji3.Enabled=True
EndSub
PrivateSubbianji2_Click()
Clipboard.SetTextText1.SelText
EndSub
PrivateSubbianji3_Click()
Clipboard.SetTextText1.SelText
Text1.SelText=""
EndSub
PrivateSubbianji4_Click()
Text1.SelText=Clipboard.GetText
EndSub
PrivateSubdahao_Click()
Text1.FontSize=20
EndSub
PrivateSubForm_Load()‘可以在这里设置密码
'DimpasswordAsString
'password=InputBox("请输入密码","密码框")
'DoWhilepassword<>"12345"
'password=InputBox("请输入密码","密码框")
'Loop
EndSub
PrivateSubForm_Resize()
Text1.Top=Form1.ScaleTop+Toolbar1.Height
Text1.Left=Form1.ScaleLeft
Text1.Width=Form1.ScaleLeft+Form1.Width-100
Text1.Height=Form1.ScaleTop+Form1.Height-650-Toolbar1.Height
EndSub
PrivateSubheiti_Click()
Text1.Font="黑体"
heiti.Enabled=False
songti.Enabled=True
kaiti.Enabled=True
lishu.Enabled=True
EndSub
PrivateSubjiacu_Click()
Ifcheck1=FalseThen
Text1.FontBold=True
jiacu.Checked=True
check1=Notcheck1
Else
Text1.FontBold=False
jiacu.Checked=False
check1=Notcheck1
EndIf
EndSub
PrivateSubkaiti_Click()
Text1.Font="楷体"
heiti.Enabled=True
songti.Enabled=True
kaiti.Enabled=False
lishu.Enabled=True
EndSub
PrivateSublishu_Click()
Text1.Font="隶书"
heiti.Enabled=True
songti.Enabled=True
kaiti.Enabled=True
lishu.Enabled=False
EndSub
PrivateSubmyabout_Click()
MsgBox"这是一个简单的菜单事例,其中包括输入、输出框的使用",vbOKOnly+vbInformation,"帮助"
EndSub
PrivateSubmyblack_Click()
Text1.ForeColor=RGB(0,0,0)
EndSub
PrivateSubmyblue_Click()
Text1.ForeColor=RGB(0,0,255)
EndSub
PrivateSubmyclear_Click()
Text1.Text=""
EndSub
PrivateSubmyexit_Click()
my1=MsgBox("是否保存文件?
",vbYesNoCancel+vbQuestion,"提示")
Ifmy1=vbYesThen
Callmysave_Click
End
Else
Ifmy1=vbNoThen
End
EndIf
EndIf
EndSub
PrivateSubmygreen_Click()
Text1.ForeColor=RGB(0,255,0)
EndSub
PrivateSubmynew_Click()
StaticlDocumentCountAsLong
DimfrmDAsForm1
lDocumentCount=lDocumentCount+1
Form1.Caption="文档"&lDocumentCount
Form1.Show
Text1.Text=""
EndSub
PrivateSubmyopen_Click()
DimfsoAsFileSystemObject,filAsFile,tsAsTextStream
'OnErrorGoToerrhandler
CommonDialog1.Filter="allfiles(*.*)|*.*|textfiles(*.txt)|*.txt|batchfiles(*.bat)"
CommonDialog1.ShowOpen
Setfso=CreateObject("Scripting.FileSystemObject")
Setfil=fso.GetFile(CommonDialog1.FileName)
Setts=fil.OpenAsTextStream(ForReading)
Text1.Text=ts.ReadAll
ts.Close
Form1.Caption=CommonDialog1.FileName
'errhandler:
'ExitSub
EndSub
PrivateSubmyred_Click()
Text1.ForeColor=RGB(255,0,0)
EndSub
PrivateSubmysave_Click()
DimfsoAsFileSystemObject,filAsTextStream
Ifmyfilename=""Then
OnErrorGoToerrhandler
CommonDialog1.Filter="allfiles(*.*)|*.*|textfiles(*.txt)|*.txt|batchfiles(*.bat)"
CommonDialog1.ShowSave
Setfso=CreateObject("Scripting.FileSystemObject")
myfilename=CommonDialog1.FileName
Setfil=fso.CreateTextFile(CommonDialog1.FileName,ForWriting)
fil.Write(Text1.Text)
fil.Close
Else
Setfso=CreateObject("Scripting.FileSystemObject")
Setfil=fso.CreateTextFile(myfilename,ForWriting)
fil.Write(Text1.Text)
fil.Close
EndIf
Form1.Caption=myfilename
errhandler:
ExitSub
EndSub
PrivateSubmysaveas_Click()
DimfsoAsFileSystemObject,filAsTextStream
OnErrorGoToerrhandler
CommonDialog1.Filter="allfiles(*.*)|*.*|textfiles(*.txt)|*.txt|batchfiles(*.bat)"
CommonDialog1.ShowSave
Setfso=CreateObject("Scripting.FileSystemObject")
myfilename=CommonDialog1.FileName
Setfil=fso.CreateTextFile(CommonDialog1.FileName,ForWriting)
fil.Write(