?? treeview
字號:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "TreeView 的基本操作"
ClientHeight = 5775
ClientLeft = 60
ClientTop = 345
ClientWidth = 7500
LinkTopic = "Form1"
ScaleHeight = 5775
ScaleWidth = 7500
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton Command4
Caption = "改變背景"
Height = 495
Left = 5880
TabIndex = 4
Top = 3960
Width = 1215
End
Begin MSComctlLib.ImageList ImageList1
Left = 6720
Top = 4560
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 1
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "TreeView的基本.frx":0000
Key = ""
EndProperty
EndProperty
End
Begin VB.CommandButton Command3
Caption = "刪除節(jié)點"
Height = 495
Left = 5880
TabIndex = 3
Top = 2960
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "增加分節(jié)點"
Height = 495
Left = 5880
TabIndex = 2
Top = 1960
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "增加頂節(jié)點"
Height = 495
Left = 5880
TabIndex = 1
Top = 960
Width = 1215
End
Begin MSComctlLib.TreeView TreeView1
Height = 5295
Left = 240
TabIndex = 0
Top = 240
Width = 5175
_ExtentX = 9128
_ExtentY = 9340
_Version = 393217
LineStyle = 1
Style = 7
ImageList = "ImageList1"
Appearance = 1
End
Begin VB.Menu mnuPopUp
Caption = "aa"
Visible = 0 'False
Begin VB.Menu a1
Caption = "增加頂節(jié)點"
End
Begin VB.Menu a2
Caption = "增加分節(jié)點"
End
Begin VB.Menu a3
Caption = "刪除節(jié)點"
End
Begin VB.Menu a4
Caption = "改變背景"
End
Begin VB.Menu end
Caption = "程序結(jié)束"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim index As Integer
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&
Private Sub a1_Click()
add1
End Sub
Private Sub a2_Click()
add2
End Sub
Private Sub a3_Click()
del
End Sub
Private Sub a4_Click()
color
End Sub
Private Sub Command1_Click() '增加頂節(jié)點
add1
End Sub
Private Sub Command2_Click() '在你所點擊的Node下新增分節(jié)點
add2
End Sub
Private Sub Command3_Click() '刪除節(jié)點
del
End Sub
Private Sub Command4_Click()
color
End Sub
Private Sub end_Click()
End
End Sub
Private Sub Form_Load()
index = 1
add1
add1
End Sub
Private Sub TreeView1_Click() '點擊TreeView時發(fā)生
index = TreeView1.SelectedItem.index '得到你所選中的節(jié)點
End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) '單擊右鍵時發(fā)生
Dim nod As Node
If Button = vbRightButton Then '檢測鼠標的點擊
Set nod = TreeView1.HitTest(x, y) '返回你所點擊的Node對象的坐標,不過也可以不要(程序運行沒有出現(xiàn)問題)
On Error GoTo EmptyNode
nod.Selected = True '設(shè)置你所點擊的Node對象被選中,不過也可以不要(程序運行沒有出現(xiàn)問題)
On Error GoTo 0
'<<下面是你的自定義菜單>>
Me.PopupMenu mnuPopUp
EmptyNode:
On Error GoTo 0
End If
End Sub
Sub add2() '增加分節(jié)點
On Error GoTo err
TreeView1.Nodes.Add index, tvwChild, , "分節(jié)點", 1 '增加頂節(jié)點
Exit Sub
err:
TreeView1.Nodes.Add , tvwLast, , "頂節(jié)點 ", 1 '增加頂節(jié)點
End Sub
Sub add1() '增加頂節(jié)點
TreeView1.Nodes.Add , tvwLast, , "頂節(jié)點", 1
End Sub
Sub del() '刪除所選節(jié)點
On Error GoTo err
TreeView1.Nodes.Remove index '刪除你所選中的節(jié)點
err:
Exit Sub
End Sub
Sub color()
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
'改變背景到紅色
lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -