相关知识点
Multiline:文本框多行输入,设置为True,手动换行是Ctrl+Enter;如果设置WordWrap属性设置为True为自动换行
ScrollBars:是否显示滚动条
ListBox:列表框
Listbox.RowSource=”sheet1!D1:”D66”:列表框的条目,不可以与List属性同时使用
Initialize:窗体初始化时
AddItem:列表框添加一个条目
RemoveItem num: 按照条目编号删除条目,编号从零开始
ListBox1.Value:就是选中的列表内的那个条目内容
ListIndex:选中条目的序号(从0开始),未做任何操作返回-1
ComboBox:下拉式列表框,与列表框用法相似
例1 当窗体被创建时,列表框的List属性,变体类型
Private Sub userForm_Initialize()
Dim a(4) as string
a(0)=”光”
a(1)=”空气”
a(2)=”土地”
a(3)=”水”
a(4)=”食物”
ListBox1.List=a
End Sub
例2 添加条目方法3
Private Sub commandButton1_Click()
ListBox1.AddItem”货币”
End Sub
例3 鼠标点中删除,没有选中就会出错,必须加判断语句
Private Sub commandButton1_Click()
If not IsNull(Listbox1.value) Then
Msgbox ListBox1.value
End If
End Sub
例4 选中列表框的条目,点击按钮将内容写入文本框
Private Sub commandButton1_Click()
Dim i as long
If Listbox1.listindex >-1 then
i=listbox1.listindex+2
textscore1.text=cells(i,3)
textscore2.text=cells(i,4)
textscore3.text=cells(i,5)
textscore4.text=cells(i,6)
textscore5.text=cells(i,7)
End If
End Sub
如果是直接选择:当用户选择发生变化时,触发事件。ListBox1_chang