请问用VB中的Load Label(i)的方式为何不能创建控件数组?

yuanhaili 2000-06-13 11:55:00
我是在98下进行开发的,用的是VB6.0英文版,是不是VB6.0英文版有bug,需要Service Patch x的补丁呀!或98需要补丁呀!请大侠明示!多谢!
...全文
225 4 打赏 收藏 转发到动态 举报
写回复
用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版数字排序拼图小游戏 Option Explicit Dim Label2X As Integer '记录标签控件数组要移动的标签控件左上角X的位置 Dim Label2Y As Integer '记录标签控件数组要移动的标签控件左上角Y的位置 '让标签数组的每个标签控件上显示的数字是随机的,无重复的 Private Sub Init() Randomize Dim a(7) As Integer Dim i As Integer, k As Integer Label1.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 Label2(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 '让空白标签Label1出现的位置随机 Randomize '记录下空白标签Label1的位置 x = Label1.Left y = Label1.Top z = Int(Rnd * 8) '将空白标签Label1和标签控件数组任一控件交换位置 Label1.Move Label2(z).Left, Label2(z).Top Label2(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 '在标签显示游戏说明信息 Label3.Caption = "如左图所示,将数字按0-7顺" & vbCrLf & vbCrLf & "序依次排列,即取得胜利。" '在标签显示排列规则后的数字顺序 Label1.Caption = 0 For i = 0 To 6 Label2(i).Caption = i + 1 Next End Sub Private Sub Label1_DragDrop(Source As Control, x As Single, y As Single) Dim Label1X As Integer '记录空白控件Label1左上角X的位置 Dim Label1Y As Integer '记录空白控件Label1左上角Y的位置 Dim flag(3) As Boolean '获取空白控件Label1的位置 Label1X = Label1.Left Label1Y = Label1.Top '要移动的控件位于空白控件Label1的正左侧 flag(0) = (Label2X = Label1X - Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正右侧 flag(1) = (Label2X = Label1X + Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正上方 flag(2) = (Label2X = Label1X) And (Label2Y = Label1Y - Source.Height) '要移动的控件位于空白控件Label1的正下方 flag(3) = (Label2X = Label1X) And (Label2Y = Label1Y + Source.Height) If flag(0) Or flag(1) Or flag(2) Or flag(3) Then Label1.Move Label2X, Label2Y Source.Move Label1X, Label1Y End If Win End Sub Private Sub Label2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then '如果按下鼠标左键 '记录下要拖动控件的位置 Label2X = Label2(Index).Left Label2Y = Label2(Index).Top Label2(Index).Drag 1 '启动拖动操作 End If End Sub Private Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Label2(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 Label2(i).Left = 0 And Label2(i).Top = 0 And _ Label2(i).Caption = 0 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 1 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 2 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 3 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 4 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 5 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 6 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 2 * Label2(i).Height And _ Label2(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 = vbYes 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 '关闭文件 Label1(1) = txt(1) Label1(1).Top = Command1.Height Label1(1).Left = 0 Label1(1).Width = Form1.Width '加载label控件数组并读入文本 For n = 2 To Lines Load Label1(n) 'Form1.width = Label1(n).width Label1(n).Left = 0 Label1(n).AutoSize = True Label1(n).WordWrap = True Label1(n).Width = Form1.Width Label1(n).Caption = txt(n) Label1(n).Visible = True Label1(n).Top = Label1(n - 1).Height + Label1(n - 1).Top Label1(n).Left = Label1(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 '设置label1控件数组内容的属性 For i = 1 To w Label1(i).FontName = CommonDialog1.FontName Label1(i).FontBold = CommonDialog1.FontBold Label1(i).FontItalic = CommonDialog1.FontItalic Label1(i).FontSize = CommonDialog1.FontSize Label1(i).FontStrikethru = CommonDialog1.FontStrikethru Label1(i).FontUnderline = CommonDialog1.FontUnderline Label1(i).ForeColor = CommonDialog1.Color Label1(i).AutoSize = True Label1(i).WordWrap = True '根据label1控件数组的大小进行重新排列 For n = 2 To w Label1(n).Top = Label1(n - 1).Top + Label1(n - 1).Height Next Next errhandler: Exit Sub End Sub Private Sub Command5_Click() End End Sub Private Sub Command6_Click() Command6.Visible = False '再次打开文件时卸载label1控件数组 For n = 2 To w Unload Label1(n) Next End Sub Private Sub Command7_Click() '从头显示文件内容 Label1(1).Top = Command1.Height For i = 2 To w Label1(i).Top = Label1(i - 1).Top + Label1(i - 1).Height Next End Sub Private Sub Form_Load() Timer1.Interval = 300 End Sub Private Sub Label1_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 Label1(i).Top = Label1(i).Top - 90 Next '到达文件尾自动停止滚屏并显示命令按钮 If Label1(w).Top + Label1(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
1 , vb5dialog.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 , vbo_progbar.zipImplement a common control progress bar with added features that are not accessable using COMCTL32.OCX! 4 , vbo_infolabel.zipThis control adds a great user-friendly interface with and icon and "Hover" ability. Based on a control seen in ICQ. 5 , vbo_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 , vbo_controlframe.zipCreate your own system button such as a Maximize, Minimize, Close, and many others with ease! 7 , vbo_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 , Label3D.zipTh
关于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属性,只要加上一行程序就可以了。 例如:Label1.ToolTipText = "这是提示!"。 5、 如何获得当前软件的运行磁盘目录和命令行参数? VB里面有个系统对象叫App。App.Path就是当前软件的运行目录。而命令行参数存放在一个系统变量里面,叫Command。程序语句如下: 引用: Label1.Caption=App.Path Label2.Caption=Command$ 6、我想换掉鼠标显示的形状,怎么做? VB提供的系统控件一般都有MousePointer和MouseIcon属性。我们可以寻找自己喜欢的*.ICO,*.CUR文件,实现的程序如下: Screen.MousePointer= 99 ’用户鼠标类型 Screen.MouseIcon=LoadPicture("C:\ABC\1.ICO") ’读取鼠标的图标文件 7、如何设置程序的错误出口? On Error语句用于程序的错误出口处理。一般的处理方法有两种: 1) 遇到错误跳转到某一行程序去执行,On Error GoTo someline。 例如: 引用: On Error GoTo ERR_LINE ... Label1.Caption=“正确执行” ERR_LINE: ... Label1.Caption=“出错了!” 2) 遇到错误之后忽略当前错误,继续执行,On Error Resume Next。 例如: 引用: On Error Resume Next ... Label1.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
一个贪吃蛇游戏 只有 36k建18个image控件组 名为 sn(0) ;sn(1) ...sn (17)一个timer1 一个label2 用来记分三个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 = 2Label2.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 Label2.Caption = Label2.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 "你死了", vbOKOnly, ""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

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧