📄 例[6-14].frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "例[6-14] 列表框项目添加和删除"
ClientHeight = 2445
ClientLeft = 60
ClientTop = 345
ClientWidth = 3900
LinkTopic = "Form1"
ScaleHeight = 2445
ScaleWidth = 3900
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 390
Left = 480
TabIndex = 3
Text = "Text1"
Top = 1785
Width = 2055
End
Begin VB.ListBox List1
Height = 1140
Left = 2040
TabIndex = 2
Top = 240
Width = 975
End
Begin VB.OptionButton Option2
Caption = "删除项目"
Height = 375
Left = 360
TabIndex = 1
Top = 840
Width = 1095
End
Begin VB.OptionButton Option1
Caption = "添加项目"
Height = 375
Left = 360
TabIndex = 0
Top = 240
Width = 1095
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Click()
If Option1.Value = True Then '判断"添加项目"单选钮是否选中
Text1.Text = InputBox("请输入要添加的项目") '从键盘输入项目放入文本框
List1.AddItem Text1.Text '把文本框内容添加到列表框
End If
If Option2.Value = True Then
Text1.Text = InputBox("请输入要删除的项目")
'遍历列表框中的每一项,如果项目内容与文本框内容相同,则删除该项,Index从0开始
For i = 0 To List1.ListCount - 1 '
If List1.List(i) = Text1.Text Then
List1.RemoveItem i
End If
Next i
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -