📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3810
ClientLeft = 60
ClientTop = 450
ClientWidth = 6840
LinkTopic = "Form1"
ScaleHeight = 3810
ScaleWidth = 6840
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command2
Caption = "删除"
Height = 375
Left = 1920
TabIndex = 12
Top = 2880
Width = 855
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 600
TabIndex = 11
Top = 2880
Width = 975
End
Begin MSComctlLib.ListView ListView1
Height = 2895
Left = 3360
TabIndex = 10
Top = 360
Width = 3255
_ExtentX = 5741
_ExtentY = 5106
View = 3
LabelWrap = -1 'True
HideSelection = 0 'False
FlatScrollBar = -1 'True
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 5
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "姓名"
Object.Width = 1834
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Text = "电话"
Object.Width = 2011
EndProperty
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 2
Text = "QQ"
Object.Width = 1869
EndProperty
BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 3
Text = "E-mail"
Object.Width = 2894
EndProperty
BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 4
Text = "地址"
Object.Width = 3246
EndProperty
End
Begin VB.TextBox Text1
Height = 270
Index = 4
Left = 960
TabIndex = 9
Text = "Text1"
Top = 2400
Width = 1935
End
Begin VB.TextBox Text1
Height = 270
Index = 3
Left = 960
TabIndex = 8
Text = "Text1"
Top = 1920
Width = 1935
End
Begin VB.TextBox Text1
Height = 270
Index = 2
Left = 960
TabIndex = 7
Text = "Text1"
Top = 1440
Width = 1935
End
Begin VB.TextBox Text1
Height = 270
Index = 1
Left = 960
TabIndex = 6
Text = "Text1"
Top = 960
Width = 1935
End
Begin VB.TextBox Text1
Height = 270
Index = 0
Left = 960
TabIndex = 5
Text = "Text1"
Top = 480
Width = 1935
End
Begin VB.Label Label6
Alignment = 2 'Center
BackColor = &H00FF0000&
BorderStyle = 1 'Fixed Single
Caption = "梦蝶网(http://dreamdee.126.com)"
ForeColor = &H00FFFFFF&
Height = 255
Left = 0
TabIndex = 13
Top = 3600
Width = 6855
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "地址:"
Height = 180
Left = 240
TabIndex = 4
Top = 2400
Width = 450
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "E-mail:"
Height = 180
Left = 240
TabIndex = 3
Top = 1920
Width = 630
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "QQ:"
Height = 180
Left = 240
TabIndex = 2
Top = 1440
Width = 270
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "电话:"
Height = 180
Left = 240
TabIndex = 1
Top = 1080
Width = 450
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "姓名:"
Height = 180
Left = 240
TabIndex = 0
Top = 480
Width = 450
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim fileName As String
Private Sub Command1_Click()
'将文本框中的信息添加到列表框中
Dim i As Integer
With ListView1.ListItems.Add()
.Text = Text1(0)
For i = 1 To 4
.SubItems(i) = Text1(i)
Next i
End With
End Sub
Private Sub Command2_Click()
'删除列表框中信息
If ListView1.ListItems.Count > 0 Then
If MsgBox("真的要删除吗?", vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
ListView1.ListItems.Remove ListView1.SelectedItem.Index
End If
End If
End Sub
Private Sub Form_Load()
Dim tpStr As String, i As Integer, j As Integer
Me.Caption = "通讯录"
For j = 0 To 4
Text1(j).Text = ""
Next j
fileName = App.Path & "\data.txt"
If Dir(fileName) <> "" Then
'加载数据
Open fileName For Input As #1
Do While Not EOF(1)
With ListView1.ListItems.Add()
For i = 0 To 4
Line Input #1, tpStr
If i = 0 Then
.Text = tpStr
Else
.SubItems(i) = tpStr
End If
Next i
End With
Loop
Close #1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
Dim tpList As ListItem
'保存数据
Open fileName For Output As #1
For Each tpList In ListView1.ListItems
Print #1, tpList.Text
For i = 1 To 4
Print #1, tpList.SubItems(i)
Next i
Next tpList
Close #1
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -