Under normal circumstances, TreeView's background color cannot be modified, we can achieve it through the API, the source code is as follows
Option expedition
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As LongPrivate Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long BYVAL NINDEX As Long) As longprivate declare function setwindowlong lib "user32" alias "setwindowlonga" (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 flow_load ()
DIM Nodex As Nodedim I as Integerdim LStyle As Long
Call SendMessage (TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB (255, 0, 0)) lStyle = GetWindowLong (TreeView1.hWnd, GWL_STYLE) Call SetWindowLong (TreeView1.hWnd, GWL_STYLE, lStyle - TVS_HASLINES) Call SetWindowLong (TreeView1.hWnd , Gwl_style, lservele)
TreeView1.Style = tvwTreelinesPlusMinusPictureTextTreeView1.BorderStyle = ccFixedSingleWith TreeView1.NodesSet nodex = .Add (,, "R", "Root") nodex.BackColor = RGB (255, 0, 0) For i = 1 To 10 Set nodex = .Add ("R", TVWChild, "C" & I, "Child" & i) Nodex.backcolor = RGB (255, 0, 0) Nodex.ensurevisiblenextend with
End Sub