在通常情况下,treeview的背景色是不可以修改的,我们可以通过api实现,源码如下 option explicit 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 const gwl_style = -16& private sub form_load() dim nodex as node call sendmessage(treeview1.hwnd, tvm_setbkcolor, 0, byval rgb(255, 0, 0)) treeview1.style = tvwtreelinesplusminuspicturetext end sub 完
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 tvm_setbkcolor = 4381&
private const tvm_getbkcolor = 4383&
private const tvs_haslines = 2&
dim i as integer
dim lstyle as long
lstyle = getwindowlong(treeview1.hwnd, gwl_style)
call setwindowlong(treeview1.hwnd, gwl_style, lstyle - tvs_haslines)
call setwindowlong(treeview1.hwnd, gwl_style, lstyle)
treeview1.borderstyle = ccfixedsingle
with treeview1.nodes
set 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.ensurevisible
next
end with