乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 49|回复: 3

动态控件的广告事件

[复制链接]

4

主题

13

帖子

2

银币

初来乍到

Rank: 1

铜币
29
发表于 2006-3-28 19:22:24 | 显示全部楼层 |阅读模式
嗨,我有这个问题:
我创建了一个函数来动态创建标签和文本控件
但是我不能将任何事件与我用该函数动态创建的每个控件相关联!
谁能帮帮我,拜托!
函数ad _ Control(LBL As String)
Set COM _ label = FRM _ tavoleupdate . MP _ 01。Pages(0).Controls.Add("Forms。Label.1 "," lbl_" lbl,Visible)
与COM_label
。Left = 5
高度=步长。Top = startY。宽度= 85
。Caption = lbl。Enabled = True。WordWrap = False。text align = fmtextalign right
End With
Set COM _ txt = FRM _ tavoleupdate . MP _ 01。Pages(0).Controls.Add("Forms。TextBox.1 "," txt_" & lbl,Visible)
与COM_txt
。Left = 120
高度=步长。Top = startY。宽度= 85
。Enabled = True。word wrap = False
End With
startY = startY+step
End函数

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

2

主题

37

帖子

2

银币

初来乍到

Rank: 1

铜币
45
发表于 2006-3-28 19:35:07 | 显示全部楼层
为了响应动态创建控件的事件,您需要在代码的常规声明部分中为该控件声明一个变量。
例如,这里是我编写的一个类的一些摘录。它基本上用它动态生成的控件填充了一个图片框。它是为VB编写的,但同样的想法适用于VBA。
在常规声明部分
  1. Private lUserLabel As Label
  2. Private WithEvents lUserTextbox As TextBox
  3. Private lDateLabel As Label
  4. Private WithEvents lDateTextbox As TextBox
  5. Private lTypeLabel As Label
  6. Private WithEvents lTypeTextbox As TextBox
  7. Private lDescriptionLabel As Label
  8. Private WithEvents lDescriptionTextbox As RichTextBox
  9. Private lIDLabel As Label
  10. Private WithEvents lIDTextbox As TextBox
  11. Private lLine As Line
  12. Private WithEvents lContainer As PictureBox
  13. Private lColor As Long
  1. Public Sub Init()
  2. On Error GoTo Trap
  3. ErrorTypes.Form.Controls.Remove "cPicturebox" & ErrorTypes.Count
  4. Set lContainer = ErrorTypes.Form.Controls.Add("VB.Picturebox", "cPicturebox" & ErrorTypes.Count, ErrorTypes.PBox)
  5. ErrorTypes.Form.Controls.Remove "cIDLabel" & ErrorTypes.Count
  6. Set lIDLabel = ErrorTypes.Form.Controls.Add("VB.Label", "cIDLabel" & ErrorTypes.Count, lContainer)
  7. ErrorTypes.Form.Controls.Remove "cIDTextbox" & ErrorTypes.Count
  8. Set lIDTextbox = ErrorTypes.Form.Controls.Add("VB.Textbox", "cIDTextbox" & ErrorTypes.Count, lContainer)
  9. ErrorTypes.Form.Controls.Remove "cUserLabel" & ErrorTypes.Count
  10. Set lUserLabel = ErrorTypes.Form.Controls.Add("VB.Label", "cUserLabel" & ErrorTypes.Count, lContainer)
  11. ErrorTypes.Form.Controls.Remove "cUserTextbox" & ErrorTypes.Count
  12. Set lUserTextbox = ErrorTypes.Form.Controls.Add("VB.Textbox", "cUserTextbox" & ErrorTypes.Count, lContainer)
  13. ErrorTypes.Form.Controls.Remove "cDateLabel" & ErrorTypes.Count
  14. Set lDateLabel = ErrorTypes.Form.Controls.Add("VB.Label", "cDateLabel" & ErrorTypes.Count, lContainer)
  15. ErrorTypes.Form.Controls.Remove "cDateTextbox" & ErrorTypes.Count
  16. Set lDateTextbox = ErrorTypes.Form.Controls.Add("VB.Textbox", "cDateTextbox" & ErrorTypes.Count, lContainer)
  17. ErrorTypes.Form.Controls.Remove "cTypeLabel" & ErrorTypes.Count
  18. Set lTypeLabel = ErrorTypes.Form.Controls.Add("VB.Label", "cTypeLabel" & ErrorTypes.Count, lContainer)
  19. ErrorTypes.Form.Controls.Remove "cTypeTextbox" & ErrorTypes.Count
  20. Set lTypeTextbox = ErrorTypes.Form.Controls.Add("VB.Textbox", "cTypeTextbox" & ErrorTypes.Count, lContainer)
  21. ErrorTypes.Form.Controls.Remove "cDescriptionLabel" & ErrorTypes.Count
  22. Set lDescriptionLabel = ErrorTypes.Form.Controls.Add("VB.Label", "cDescriptionLabel" & ErrorTypes.Count, lContainer)
  23. ErrorTypes.Form.Controls.Remove "cDescriptionTextbox" & ErrorTypes.Count
  24. Set lDescriptionTextbox = ErrorTypes.Form.Controls.Add("RichText.RichTextCTRL.1", "cDescriptionTextbox" & ErrorTypes.Count, lContainer)
  25. With lContainer
  26.     .Visible = True
  27.     '.ScaleHeight = 1050
  28.     'mvarHeight = .Height
  29.     '.ScaleWidth = ErrorTypes.PBox.Width
  30.     .Appearance = 0
  31.     .BorderStyle = 0
  32.     .BackColor = vbWhite
  33.     End With
  34. With lIDLabel
  35.     .Visible = True
  36.     .Caption = " " & mvarSType & " ID: "
  37.     .BackColor = 14408667
  38.     .AutoSize = True
  39.     End With
  40. With lIDTextbox
  41.     .Visible = True
  42.     .Text = mvarID
  43.     .BorderStyle = 0
  44.     .BackColor = 14408667
  45.     .Height = lIDLabel.Height
  46.     .Locked = True
  47.     End With
  48. With lUserLabel
  49.     .Visible = True
  50.     .Caption = "User: "
  51.     .BackColor = 14408667
  52.     '.AutoSize = True
  53.     End With
  54. With lUserTextbox
  55.     .Visible = True
  56.     .Text = mvarUser
  57.     .BorderStyle = 0
  58.     .BackColor = 14408667
  59.     .Height = lUserLabel.Height
  60.     .Locked = True
  61.     End With
  62. With lDateLabel
  63.     .Visible = True
  64.     .Caption = "Date: "
  65.     .BackColor = 14408667
  66.     '.AutoSize = True
  67.     End With
  68. With lDateTextbox
  69.     .Visible = True
  70.     .Text = mvarTimestamp
  71.     .BorderStyle = 0
  72.     .BackColor = 14408667
  73.     .Height = lDateLabel.Height
  74.     .Locked = True
  75.     End With
  76. With lTypeLabel
  77.     .Visible = True
  78.     .Caption = " Label: "
  79.     .BackColor = vbWhite
  80.     '.AutoSize = True
  81.     End With
  82. With lTypeTextbox
  83.     .Visible = True
  84.     .Text = mvarEType
  85.     .Height = lTypeLabel.Height
  86.     .Locked = True
  87.     End With
  88. With lDescriptionLabel
  89.     .Visible = True
  90.     .Caption = "Notes: "
  91.     .BackColor = vbWhite
  92.     '.AutoSize = True
  93.     End With
  94. With lDescriptionTextbox
  95.     .Visible = True
  96.     .Text = mvarDescription
  97.     .Height = (((ErrorTypes.Form.TextWidth(mvarDescription) - 150) \ .Width) + 1) * ErrorTypes.Form.TextHeight(mvarDescription) + 150 'lDescriptionLabel.Height
  98.     .Locked = True
  99.     End With
  100. Exit Sub
  101. Trap:
  102. Select Case Err.Number
  103.     Case 730
  104.         Resume Next
  105.     Case Else
  106.         Exit Sub
  107.     End Select

回复

使用道具 举报

2

主题

37

帖子

2

银币

初来乍到

Rank: 1

铜币
45
发表于 2006-3-28 19:40:27 | 显示全部楼层
哦,是的,这是lContainer_Resize()事件。(lContainer是我在一般声明部分声明的变量)
现在,您可能需要研究控件数组。我不确定您是否可以声明这样的
并使其产生与控件数组等效的变量。
回复

使用道具 举报

4

主题

13

帖子

2

银币

初来乍到

Rank: 1

铜币
29
发表于 2006-3-29 03:53:58 | 显示全部楼层

Tnx家伙,我会试试的!
我让你知道!
/r
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-6 05:59 , Processed in 0.913215 second(s), 61 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表