社区
控件
帖子详情
请问用VB中的Load Label(i)的方式为何不能创建控件数组?
yuanhaili
2000-06-13 11:55:00
我是在98下进行开发的,用的是VB6.0英文版,是不是VB6.0英文版有bug,需要Service Patch x的补丁呀!或98需要补丁呀!请大侠明示!多谢!
...全文
225
4
打赏
收藏
请问用VB中的Load Label(i)的方式为何不能创建控件数组?
我是在98下进行开发的,用的是VB6.0英文版,是不是VB6.0英文版有bug,需要Service Patch x的补丁呀!或98需要补丁呀!请大侠明示!多谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sc74
2000-06-16
打赏
举报
回复
先在form中创建一Label,名为MYLabel。然后在属性表中将"Index"属性设为数字“0”,(注意其默认值是空值),接下来在form的load事件中用语句 Load MYLabel(i).
mafangsan
2000-06-13
打赏
举报
回复
完全可以!我用的也是VB6.0英文版,TopHead说的对,首先要人为创建一个控件数组,而且用Load Label(i)的方式创建的控件Visible属性为False,你设置好它的Left和Top再将其Visible设为True就出来了。
TopHead
2000-06-13
打赏
举报
回复
可以啊,但是必须首先创建一个Label(0)才行!
Limu
2000-06-13
打赏
举报
回复
mafangsan have given a detail answer.
VB
版数字排序拼图小游戏
VB
版数字排序拼图小游戏 Option Explicit Dim
Label
2X As Integer '记录标签
控件
数组
中
要移动的标签
控件
左上角X的位置 Dim
Label
2Y As Integer '记录标签
控件
数组
中
要移动的标签
控件
左上角Y的位置 '让标签
数组
中
的每个标签
控件
上显示的数字是随机的,无重复的 Private Sub Init() Randomize Dim a(7) As Integer Dim i As Integer, k As Integer
Label
1.Caption = "" For i = 0 To 7 a(i) = i Next For i = 0 To 7 k = Int(Rnd * 8) Do While a(k) = -1 'a(k)=-1表示该
数组
元素对应的数字已经被使用过了 k = Int(Rnd * 8) '重新生成k的值,直到a(k)的值不等于-1 Loop
Label
2(i).Caption = Trim(Str(a(k))) a(k) = -1 'a(k)的值已经使用了,
不能
再用,重新赋值为-1与其他的元素值相区别 Next i End Sub Private Sub cb_Click() MsgBox "欢迎观临 陈彬 020901033" End Sub Private Sub Command1_Click() Dim x As Integer, y As Integer Dim z As Integer Init Picture1.Enabled = True '让空白标签
Label
1出现的位置随机 Randomize '记录下空白标签
Label
1的位置 x =
Label
1.Left y =
Label
1.Top z = Int(Rnd * 8) '将空白标签
Label
1和标签
控件
数组
任一
控件
交换位置
Label
1.Move
Label
2(z).Left,
Label
2(z).Top
Label
2(z).Move x, y Command1.Enabled = False End Sub Private Sub Command2_Click() End End Sub Private Sub Form_
Load
() Dim i As Integer Picture1.Enabled = False '在标签
中
显示游戏说明信息
Label
3.Caption = "如左图所示,将数字按0-7顺" &
vb
CrLf &
vb
CrLf & "序依次排列,即取得胜利。" '在标签
中
显示排列规则后的数字顺序
Label
1.Caption = 0 For i = 0 To 6
Label
2(i).Caption = i + 1 Next End Sub Private Sub
Label
1_DragDrop(Source As Control, x As Single, y As Single) Dim
Label
1X As Integer '记录空白
控件
Label
1左上角X的位置 Dim
Label
1Y As Integer '记录空白
控件
Label
1左上角Y的位置 Dim flag(3) As Boolean '获取空白
控件
Label
1的位置
Label
1X =
Label
1.Left
Label
1Y =
Label
1.Top '要移动的
控件
位于空白
控件
Label
1的正左侧 flag(0) = (
Label
2X =
Label
1X - Source.Width) And (
Label
2Y =
Label
1Y) '要移动的
控件
位于空白
控件
Label
1的正右侧 flag(1) = (
Label
2X =
Label
1X + Source.Width) And (
Label
2Y =
Label
1Y) '要移动的
控件
位于空白
控件
Label
1的正上方 flag(2) = (
Label
2X =
Label
1X) And (
Label
2Y =
Label
1Y - Source.Height) '要移动的
控件
位于空白
控件
Label
1的正下方 flag(3) = (
Label
2X =
Label
1X) And (
Label
2Y =
Label
1Y + Source.Height) If flag(0) Or flag(1) Or flag(2) Or flag(3) Then
Label
1.Move
Label
2X,
Label
2Y Source.Move
Label
1X,
Label
1Y End If Win End Sub Private Sub
Label
2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) If Button =
vb
LeftButton Then '如果按下鼠标左键 '记录下要拖动
控件
的位置
Label
2X =
Label
2(Index).Left
Label
2Y =
Label
2(Index).Top
Label
2(Index).Drag 1 '启动拖动操作 End If End Sub Private Sub
Label
2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
Label
2(Index).Drag 2 '结束拖动操作 End Sub Private Sub Win() Dim winner As Integer Dim i As Integer Dim answer As Integer '对于给定的标签
控件
数组
中
的任一标签
控件
,可以落在符合要求(对应位置应显示对应数字) '的八个位置
中
的任一位置 '利用循环语句对标签
控件
数组
中
的每个标签
控件
进行检查,如果其落在某一符号要求的位置, '则变量winner的值加1,如果所有标签
控件
都落在符号要求的位置,则变量winner的值应为8 For i = 0 To 7 If
Label
2(i).Left = 0 And
Label
2(i).Top = 0 And _
Label
2(i).Caption = 0 Then winner = winner + 1 ElseIf
Label
2(i).Left =
Label
2(i).Width And
Label
2(i).Top = 0 And _
Label
2(i).Caption = 1 Then winner = winner + 1 ElseIf
Label
2(i).Left = 2 *
Label
2(i).Width And
Label
2(i).Top = 0 And _
Label
2(i).Caption = 2 Then winner = winner + 1 ElseIf
Label
2(i).Left = 0 And
Label
2(i).Top =
Label
2(i).Height And _
Label
2(i).Caption = 3 Then winner = winner + 1 ElseIf
Label
2(i).Left =
Label
2(i).Width And
Label
2(i).Top =
Label
2(i).Height And _
Label
2(i).Caption = 4 Then winner = winner + 1 ElseIf
Label
2(i).Left = 2 *
Label
2(i).Width And
Label
2(i).Top =
Label
2(i).Height And _
Label
2(i).Caption = 5 Then winner = winner + 1 ElseIf
Label
2(i).Left = 0 And
Label
2(i).Top = 2 *
Label
2(i).Height And _
Label
2(i).Caption = 6 Then winner = winner + 1 ElseIf
Label
2(i).Left =
Label
2(i).Width And
Label
2(i).Top = 2 *
Label
2(i).Height And _
Label
2(i).Caption = 7 Then winner = winner + 1 End If Next i If winner = 8 Then MsgBox " 恭喜您,胜利了!", 0 + 64 + 0, "提示" Picture1.Enabled = False answer = MsgBox("还继续吗?", 4 + 32 + 0, "提示") If answer =
vb
Yes Then Command1.Enabled = True Else End End If End If End Sub
文本阅读器
Dim n As Integer, Lines As Integer, i As Integer, w As Integer, a As Boolean Private Sub Command1_Click() Command6.Visible = False a = Not a '变量开关,再次打开文件时进行判断 If a = True Then no1: Dim infile As String '打开通用对话框,获取文件名称 CommonDialog1.InitDir = "" CommonDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*" CommonDialog1.FilterIndex = 1 CommonDialog1.ShowOpen infile = CommonDialog1.FileName Dim txt() As String, Lines As Integer Lines = 0 ' 文件行数总计 Open infile For Input As #1 'infile 变量
中
存放的是文本文件的名字 While Not EOF(1) ReDim Preserve txt(Lines + 1) '开辟空间以存放一行内容 Lines = Lines + 1 Line Input #1, txt(Lines) '读入一行并放入
数组
Wend w = Lines Close #1 '关闭文件
Label
1(1) = txt(1)
Label
1(1).Top = Command1.Height
Label
1(1).Left = 0
Label
1(1).Width = Form1.Width '加载
label
控件
数组
并读入文本 For n = 2 To Lines
Load
Label
1(n) 'Form1.width =
Label
1(n).width
Label
1(n).Left = 0
Label
1(n).AutoSize = True
Label
1(n).WordWrap = True
Label
1(n).Width = Form1.Width
Label
1(n).Caption = txt(n)
Label
1(n).Visible = True
Label
1(n).Top =
Label
1(n - 1).Height +
Label
1(n - 1).Top
Label
1(n).Left =
Label
1(1).Left Next Else Call Command6_Click a = Not a GoTo no1 End If End Sub Private Sub Command2_Click() '减少interval Timer1.Interval = Timer1.Interval - 25 End Sub Private Sub Command3_Click() '增加interval Timer1.Interval = Timer1.Interval + 30 End Sub Private Sub Command4_Click() '打开“字体”对话框 CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects On Error GoTo errhandler CommonDialog1.ShowFont '设置
label
1
控件
数组
内容的属性 For i = 1 To w
Label
1(i).FontName = CommonDialog1.FontName
Label
1(i).FontBold = CommonDialog1.FontBold
Label
1(i).FontItalic = CommonDialog1.FontItalic
Label
1(i).FontSize = CommonDialog1.FontSize
Label
1(i).FontStrikethru = CommonDialog1.FontStrikethru
Label
1(i).FontUnderline = CommonDialog1.FontUnderline
Label
1(i).ForeColor = CommonDialog1.Color
Label
1(i).AutoSize = True
Label
1(i).WordWrap = True '根据
label
1
控件
数组
的大小进行重新排列 For n = 2 To w
Label
1(n).Top =
Label
1(n - 1).Top +
Label
1(n - 1).Height Next Next errhandler: Exit Sub End Sub Private Sub Command5_Click() End End Sub Private Sub Command6_Click() Command6.Visible = False '再次打开文件时卸载
label
1
控件
数组
For n = 2 To w Un
load
Label
1(n) Next End Sub Private Sub Command7_Click() '从头显示文件内容
Label
1(1).Top = Command1.Height For i = 2 To w
Label
1(i).Top =
Label
1(i - 1).Top +
Label
1(i - 1).Height Next End Sub Private Sub Form_
Load
() Timer1.Interval = 300 End Sub Private Sub
Label
1_Click(Index As Integer) '控制滚屏,及命令按钮的隐现 Timer1.Enabled = Not Timer1.Enabled Command1.Visible = Not Timer1.Enabled Command2.Visible = Not Timer1.Enabled Command3.Visible = Not Timer1.Enabled Command4.Visible = Not Timer1.Enabled Command5.Visible = Not Timer1.Enabled Command7.Visible = Not Timer1.Enabled End Sub Private Sub Timer1_Timer() For i = 1 To w
Label
1(i).Top =
Label
1(i).Top - 90 Next '到达文件尾自动停止滚屏并显示命令按钮 If
Label
1(w).Top +
Label
1(w).Height < Form1.Height - 400 Then Timer1.Enabled = False Command1.Visible = True Command2.Visible = True Command3.Visible = True Command4.Visible = True Command5.Visible = True Command7.Visible = True MsgBox "文章已经到头" End If End Sub 做
vb
VB
编程资源大全(英文源码
控件
)
1 ,
vb
5dialog.zipThis demonstrates how to subclass the Common Dialog Dialogs and manipulate a specific Dialog.2 , cpnl.zipForm_Taskbar is a control for Visual Basic which, once placed onto a form, makes the form act like the Taskbar (minus the Start Menu).3 ,
vb
o_progbar.zipImplement a common control progress bar with added features that are not accessable using COMCTL32.OCX! 4 ,
vb
o_info
label
.zipThis control adds a great user-friendly interface with and icon and "Hover" ability. Based on a control seen in ICQ. 5 ,
vb
o_checkcombo.zipAdd a checkbox to a combo box and use it to enabled/disable the combo! or whatever you would like to do with it! 6 ,
vb
o_controlframe.zipCreate your own system button such as a Maximize, Minimize, Close, and many others with ease! 7 ,
vb
o_ctextbox.zipThis class makes using the Textbox or Edit class API simple. Easily set properties and access many features not available directly from
VB
. 8 , taskbar.zipForm_Taskbar is a control for Visual Basic which, once placed onto a form, makes the form act like the Taskbar (minus the Start Menu).9 , NT_Service.zipThis is an OCX that allows you to create an NT service application...add the control to your project and register it as a service!!10 , Scroller.zipThis is a Control Container, it's like a frame control but it lets you scroll the content up and down...11 , TrayArea.zipThis control lets you add your icon to the System Tray Area and handle some events such as MouseMove, MouseDown, MouseUp and DblClick.12 , Resizer.zipThis is a very useful control: It's a container control, you can insert two controls inside and then you'll have a vertical (or horizontal) resizer bar (like the Windows File Explorer). A resizer can contain another resizer... an so on. (you can divide you form in as many sizable sections as you want...).13 ,
Label
3D.zipTh
VB
6.0初学者的10个编程小技巧
关于
vb
初学者的忠告 信息来源:邪恶八进制信息安全团队(www.eviloctal.com) 1、如果一行程序太长,能
不能
换行?
VB
的程序代码是允许换行书写的,只要在每次换行的最后一个字符加上换行字符“_”就可以了。例如: 引用: Sub PicMove() Frm.Picture2.Left = Frm.Picture1.Left + _ ’加上换行符 Frm.Picture1.Width End Sub 2、 如何在设计的时候清空存在的图片? 用鼠标点
中
该图片,在属性窗口
中
选
中
Picture属性,按Del键便可清空图片。 3、 Visual Basic 如何注释一段较长程序代码?
VB
注释程序代码的符号是“注释:”,只要在某行程序前面加上“注释:”,就可以注释该行程序。但如果程序代码很长的时候,一行一行地注释令人觉得难以忍受。
VB
本身提供了这个功能,在主菜单“视图”选项的“工具栏”下,选
中
Edit,
VB
的界面会出现一排工具按钮,其
中
的手形图标按钮后的两个按钮用于“设置注释块”和“解除注释块”。 4、怎么实现鼠标一移上去就出现小提示窗口的功能?
VB
里每个
控件
都有ToolTipText属性,只要加上一行程序就可以了。 例如:
Label
1.ToolTipText = "这是提示!"。 5、 如何获得当前软件的运行磁盘目录和命令行参数?
VB
里面有个系统对象叫App。App.Path就是当前软件的运行目录。而命令行参数存放在一个系统变量里面,叫Command。程序语句如下: 引用:
Label
1.Caption=App.Path
Label
2.Caption=Command$ 6、我想换掉鼠标显示的形状,怎么做?
VB
提供的系统
控件
一般都有MousePointer和MouseIcon属性。我们可以寻找自己喜欢的*.ICO,*.CUR文件,实现的程序如下: Screen.MousePointer= 99 ’用户鼠标类型 Screen.MouseIcon=
Load
Picture("C:\ABC\1.ICO") ’读取鼠标的图标文件 7、如何设置程序的错误出口? On Error语句用于程序的错误出口处理。一般的处理方法有两种: 1) 遇到错误跳转到某一行程序去执行,On Error GoTo someline。 例如: 引用: On Error GoTo ERR_LINE ...
Label
1.Caption=“正确执行” ERR_LINE: ...
Label
1.Caption=“出错了!” 2) 遇到错误之后忽略当前错误,继续执行,On Error Resume Next。 例如: 引用: On Error Resume Next ...
Label
1.Caption=“不管对不对都要执行” ... 8、怎样获得键盘输入和判断敲键的Ascii值? 把窗体的KeyPreview属性设置成True,然后在Form_KeyPress 事件里编写程序代码如下: 引用: Private Sub Form_KeyPress (KeyAscii As Integer) Me.Caption = Str(KeyAscii) ‘取得键盘输入的字符 ... End Sub 9、我希望窗体一运行就在屏幕的
中
央,怎么实现?
VB
的系统对象Screen记录了当前显示模式的高度和宽度,可以利用这个值来设置窗体的位置。 引用: Sub CenterForm(frm As Form) ‘定义过程 frm.Move (Screen.width - frm.width)\ 2, (Screen.Height - frm.Height) \ 2 End Sub Private Sub Form_
Load
() CenterForm Me ’调用过程 End Sub 10、很多软件都有鼠标在文本框TextBox一按下,就选
中
所有文字的功能,是怎么实现的? 引用: Private Sub Text1_GotFocus() Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) ’过程调用 End Sub 帖子3926 精华128 积分210000 阅读权限200 性别男 在线时间1119 小时 注册时间2007-10-23 最后登录2009-1-28 查看详细资料 TOP
vb
贪吃蛇 源码 --from:胡宸源
一个贪吃蛇游戏 只有 36k建18个image
控件
组 名为 sn(0) ;sn(1) ...sn (17)一个timer1 一个
label
2 用来记分三个image名为 pg;she和st 分别放苹果;蛇身和蛇头的图片所有image的长 宽 都为255一个shape 名为 sh 长宽为4590源码如下;(本人要读书,不太完善)Dim n As ByteDim cz As IntegerPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = 37 Or KeyCode = 38 Or KeyCode = 39 Or KeyCode = 40 ThenIf cz - KeyCode <> 2 Then If cz - KeyCode <> -2 Then cz = KeyCodeElseEnd IfEnd SubPrivate Sub Form_
Load
()cz = 38: n = 2
Label
2.Caption = 0Timer1.Enabled = TrueTimer1.Interval=526sn(0).Picture = st.PictureFor i = 1 To nsn(i).Picture = she.PictureNext isn(0).Top = sh.Top + 7 * 255sn(0).Left = sh.Left + 8 * 255For i = 1 To 17sn(i).Top = sn(i - 1).Top + 255sn(i).Left = sn(i - 1).LeftNext icspgEnd SubPrivate Sub Timer1_Timer()For i = 17 To 1 Step -1sn(i).Top = sn(i - 1).Topsn(i).Left = sn(i - 1).LeftNext iSelect Case czCase 37sn(0).Left = sn(0).Left - 255Case 38sn(0).Top = sn(0).Top - 255Case 39sn(0).Left = sn(0).Left + 255Case 40sn(0).Top = sn(0).Top + 255End SelectFor i = 1 To nIf sn(0).Left = sn(i).Left Then _If sn(0).Top = sn(i).Top Then slNext iIf sn(0).Top < sh.Top Or sn(0).Top > sh.Top + 4355 Then slIf sn(0).Left < sh.Left Or sn(0).Left > sh.Left + 4355 Then slIf sn(0).Left = pg.Left Then If sn(0).Top = pg.Top Then n = n + 1
Label
2.Caption =
Label
2.Caption + 100 If n = 18 Then Timer1.Enabled = False MsgBox "过关" End End If Timer1.Interval = Timer1.Interval - 35 sn(n).Picture = she.Picture cspg End IfEnd IfEnd SubSub sl()Timer1.Enabled = FalseMsgBox "你死了",
vb
OKOnly, ""EndEnd SubSub cspg()Randomize Timerx = Int(Rnd * 18)y = Int(Rnd * 18)pg.Left = sh.Left + x * 255pg.Top = sh.Top + y * 255For i = 0 To nIf pg.Left = sn(i).Left ThenIf pg.Top = sn(i).Top Then cspgEnd IfNext iEnd Sub
控件
1,451
社区成员
41,355
社区内容
发帖
与我相关
我的任务
控件
VB 控件
复制链接
扫一扫
分享
社区描述
VB 控件
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章