📄 form16.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form16
BorderStyle = 1 'Fixed Single
Caption = "Form16"
ClientHeight = 7335
ClientLeft = 45
ClientTop = 435
ClientWidth = 10215
LinkTopic = "Form16"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7335
ScaleWidth = 10215
StartUpPosition = 3 '窗口缺省
Begin MSAdodcLib.Adodc Adodc1
Height = 615
Left = 2640
Top = 6000
Width = 2535
_ExtentX = 4471
_ExtentY = 1085
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = $"Form16.frx":0000
OLEDBString = $"Form16.frx":00B6
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "图书类别"
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.TextBox Text1
Height = 375
Index = 1
Left = 3600
TabIndex = 10
Top = 1200
Width = 855
End
Begin VB.TextBox Text1
Height = 375
Index = 0
Left = 3720
TabIndex = 9
Top = 360
Width = 855
End
Begin MSComctlLib.ImageList ImageList1
Left = 1440
Top = 480
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 3
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form16.frx":016C
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form16.frx":1B93
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form16.frx":35BA
Key = ""
EndProperty
EndProperty
End
Begin VB.CommandButton Command6
Caption = "退出"
Height = 375
Left = 2760
TabIndex = 8
Top = 4800
Width = 1095
End
Begin VB.CommandButton Command5
Caption = "删除"
Height = 375
Left = 2760
TabIndex = 7
Top = 4200
Width = 1095
End
Begin VB.CommandButton Command4
Caption = "排序"
Height = 375
Left = 2760
TabIndex = 6
Top = 3600
Width = 1095
End
Begin VB.CommandButton Command3
Caption = "收起"
Height = 375
Left = 2760
TabIndex = 5
Top = 3000
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "展开"
Height = 375
Left = 2760
TabIndex = 4
Top = 2400
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 375
Left = 2760
TabIndex = 3
Top = 1800
Width = 1095
End
Begin MSComctlLib.TreeView TreeView1
Height = 3015
Left = 240
TabIndex = 0
Top = 1080
Width = 2055
_ExtentX = 3625
_ExtentY = 5318
_Version = 393217
Style = 7
Appearance = 1
End
Begin VB.Label Label2
Caption = "子"
Height = 495
Left = 2880
TabIndex = 2
Top = 1080
Width = 1095
End
Begin VB.Label Label1
Caption = "父"
Height = 375
Left = 2880
TabIndex = 1
Top = 360
Width = 1095
End
End
Attribute VB_Name = "Form16"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Integer
Dim J As Integer
Dim nodx As Node
Dim CunZai As Boolean '定义变量
Private Sub Command1_Click()
If Text1(0).Text <> "" And Text1(1).Text <> "" Then '不允许建立零字节的父节点和子节点
CunZai = False
J = TreeView1.Nodes.Count
For i = 1 To TreeView1.Nodes.Count '检查新输入的父节点名称是否存在
If TreeView1.SelectedItem.Children > 0 Then
If Text1(0).Text = TreeView1.Nodes(i).Text Then CunZai = True
End If
Next i
If CunZai = True Then '若存在, 则在父节点下建立子节点
Set nodx = TreeView1.Nodes.Add(Text1(0).Text, tvwChild, "child" & J, Text1(1).Text, 3)
Else '若不存在,则建立父节点和子节点
'Set nodx = TreeView1.Nodes.Add(, , Text1(0).Text, Text1(0).Text, 1)
Set nodx = TreeView1.Nodes.Add(Text1(0).Text, tvwChild, "child" & J, Text1(1).Text, 3)
End If
TreeView1.Refresh
ElseIf Text1(0).Text = "" Then MsgBox "请输入父节点名称!", vbInformation, "警告!"
'系统提示
ElseIf Text1(1).Text = "" Then MsgBox "请输入子节点名称!", vbInformation, "警告!"
End If
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(1) = Text1(1).Text
Adodc1.Recordset.Update
End Sub
Private Sub Command2_Click()
For i = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(i).Expanded = True '展开所有节点
Next i
End Sub
Private Sub Command3_Click()
For i = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(i).Expanded = False '收起所有节点
Next i
End Sub
Private Sub Command4_Click()
TreeView1.Sorted = True '排列顺序
End Sub
Private Sub Command5_Click()
If TreeView1.SelectedItem.Index <> 1 Then
TreeView1.Nodes.Remove TreeView1.SelectedItem.Index '删除选定的节点
End If
End Sub
Private Sub Command6_Click()
End '退出程序
End Sub
Private Sub Form_Load()
TreeView1.LineStyle = tvwTreeLines '在兄弟节点和父节点之间显示线
TreeView1.ImageList = ImageList1 '链接图像列
TreeView1.Style = tvwTreelinesPlusMinusPictureText
'树状外观包含全部元素
Set nodx = TreeView1.Nodes.Add(, , "图书类别", "图书类别", 1)
'建立名称为"蒲子明"的父节点,选择索引为1的图像
'在"蒲子明"父节点下建立"发件箱"子节点,选择索引为3的图像
CunZai = False
End Sub
Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Node.ExpandedImage = 2 '节点被展开时,选择索引为2的图像
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If TreeView1.SelectedItem.Children = 0 Then '检查是否有子节点,0为无
For i = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes(i).Selected Then
MsgBox "您选择的是:“" & TreeView1.Nodes(i).FullPath & "”子节点!"
'系统提示
End If
Next i
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -