在网上找了一下,动态添加控件的方法比较零乱。
添加按钮控件
Controls.Add("Forms.CommandButton.1", "CommandButton" & i + 2, True)
添加textbox控件
Controls.Add(bstrprogid:="Forms.TextBox.1")请各位大侠帮助的是。
在哪里能找到比较系统的控件表。
checkbox,listbox等。谢谢。
添加按钮控件
Controls.Add("Forms.CommandButton.1", "CommandButton" & i + 2, True)
添加textbox控件
Controls.Add(bstrprogid:="Forms.TextBox.1")请各位大侠帮助的是。
在哪里能找到比较系统的控件表。
checkbox,listbox等。谢谢。
Object 必需的。一个对象表达式,其值是“应用于”列表中的一个对象。
ProgID 必需的。一个标识控件的字符串。大多数控件的 ProgID 都可通过查看对象浏览器来决定。控件的 ProgID 是由控件的库和类组成的。例如,CommandButton 控件的 ProgID 是 VB.CommandButton。在 ProgID 与对象浏览器中所显示的不一样的情况下,Visual Basic 将显示一个包括正确 ProgId 的错误信息。 name 必要的。一个字符串,用来标识集合的成员。
container 可选的。一个对象引用,它指定控件的容器。如果没有指定或为 NULL,缺省值为 Controls 集合所属的容器。通过指定该参数,可以把一个控件放置在任何现存的容器控件(如 Frame 控件)中。用户控件或 ActiveX 文档也可以作为一个容器。
此示例有commandbutton,textbox和treeview控件。不是很全。' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButtonPrivate Sub ctlCommand_Click()
ctlText.Text = "You Clicked the Command button"
End SubPrivate Sub ctlDynamic_ObjectEvent(Info As EventInfo)
' test for the click event of the TreeView
If Info.Name = "Click" Then
ctlText.Text = "You clicked " & ctlDynamic.object.selecteditem.Text
End If
End SubPrivate Sub Form_Load()
Dim i As Integer
' Add the license for the treeview to the license collection.
' If the license is already in the collection you will get
' the run-time error number 732.
Licenses.Add "MSComctlLib.TreeCtrl" ' Dynamically add a TreeView control to the form.
' If you want the control to be added to a different
' container such as a Frame or PictureBox, you use the third
' parameter of the Controls.Add to specify the container.
Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", _
"myctl", Form1)
' set the location and size of the control.
ctlDynamic.Move 1, 1, 2500, 3500 ' Add some nodes to the control.
For i = 1 To 10
ctlDynamic.object.nodes.Add Key:="Test" & Str(i), Text:="Test" _
& Str(i)
ctlDynamic.object.nodes.Add Relative:="Test" & Str(i), _
Relationship:=4, Text:="TestChild" & Str(i)
Next i
' Make the control visible.
ctlDynamic.Visible = True ' add a textbox
Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
' Set the location and size of the textbox
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
1, 2500, 100 ' Change the backcolor.
ctlText.BackColor = vbYellow ' Make it visible
ctlText.Visible = True ' Add a CommandButton.
Set ctlCommand = Controls.Add("VB.CommandButton", _
"ctlCommand1", Form1) ' Set the location and size of the CommandButton.
ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
ctlText.Height + 50, 1500, 500 ' Set the caption
ctlCommand.Caption = "Click Me" ' Make it visible
ctlCommand.Visible = True
End Sub
标准控件的话在对象浏览器中都可以看到。按F2就行了。第一个列表框选择VB就会显示vb的标准控件(并不都是)。
如果是第三方控件的话先通过部件添加进来,然后在对象浏览器里也可以看到。比如Set ctlDynamic = Controls.Add("MSComctlLib.TreeCtrl", "myctl", Form1),在添加部件ms windows common controls 6.0后就可以在对象浏览器中看到,MSComctlLib是库名,TreeCtrl是控件类名。
object 必需。一个有效对象名。
Name 可选。指定被添加的对象的名称。如果没有指定名称,系统将根据使用该窗体的应用程序的规则,产生一默认的名称。
Caption 可选。指定在标签或控件上出现的题注。如果没有指定题注,系统将根据使用该窗体的应用程序的规则,产生一默认的题注。
index 可选。表示页或标签在 Pages 或 Tabs 集合中的位置。若没有规定索引,系统会将页或标签添加到 Pages 或 Tabs 集合的末尾,并赋于它相应的索引值。
ProgID 必需。程序设计标识符。是用于标识对象类的、没有空格的文本串。ProgID 的标准语法是 <Vendor>.<Component>.<Version>。ProgID 会被映射为类标识符 (CLSID)。
Visible 可选。若对象为可见的(这是默认方式)则为 True;若对象为隐藏的则为 False。
设置单个控件的 ProgID 值:复选框 Forms.CheckBox.1
组合框 Forms.ComboBox.1
命令按钮 Forms.CommandButton.1
框架 Forms.Frame.1
图像 Forms.Image.1
标签 Forms.Label.1
列表框 Forms.ListBox.1
多页 Forms.MultiPage.1
选项按钮 Forms.OptionButton.1
滚动条 Forms.ScrollBar.1
数值调节钮 Forms.SpinButton.1
TabStrip Forms.TabStrip.1
文本框 Forms.TextBox.1
切换按钮 Forms.ToggleButton.1
http://download.csdn.net/source/1675743
时间:2010-07-17 22:55:23 来自:113.96.173.*
谢谢,以后会注意说明excel-vba的工作环境,个人工作习惯是在EXCEL-VBAVB6调试程序,调试差不多,在VB6打包dll。
主要应用是在EXCEL中加载dll文件。
CheckBox Forms.CheckBox
ComboBox Forms.ComboBox
CommandButton Forms.CommandButton
Frame Forms.Frame
Image Forms.Image
Label Forms.Label
ListBox Forms.ListBox
MultiPage Forms.MultiPage
OptionButton Forms.OptionButton
ScrollBar Forms.ScrollBar
SpinButton Forms.SpinButton
TabStrip Forms.TabStrip
TextBox Forms.TextBox
切换按钮 Forms.ToggleButton