VB中如何修改treeview的背景色

2021-04-01 21:47:36 字數 3031 閱讀 7640

改變 treeview 的背景  

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&

dim frmlastform as form

private sub form_load()

dim nodx as node

set nodx = treeview1.nodes.add(, , "r", "root")

set nodx = treeview1.nodes.add("r", tvwchild, "c1", "child 1")

set nodx = treeview1.nodes.add("r", tvwchild, "c2", "child 2")

set nodx = treeview1.nodes.add("r", tvwchild, "c3", "child 3")

set nodx = treeview1.nodes.add("r", tvwchild, "c4", "child 4")

nodx.ensurevisible

treeview1.style = tvwtreelinestext ' style 4.

treeview1.borderstyle = vbfixedsingle

end sub

private sub command1_click()

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

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 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 form_load()

dim nodex as node

dim i as integer

dim 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, lstyle)

treeview1.style = tvwtreelinesplu**inuspicturetext

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

end sub

如何避免TreeView中Checked事件死迴圈

在treeview的aftercheck事件中新增處理 設定其它相關treenode的checked屬性。問題 通過 改變treenode.checked屬性同樣會觸發treeview.aftercheck事件。若節點a的狀態改變時需要自動改變節點b的選中狀態,且節點b的狀態改變時也需要自動改變節點...

請教qtp中如何操作treeview控制項

qtp中執行 window mywindow wintreeview mytreeview getitem 0 時,出了如下的錯誤 cannot identify the specified item of the tucroottree object.confirm that the specif...

Qt下TreeView修改分支樣式

f1查詢qt幫助,原文如下 自己摸索實現分支三態,如下 qtreeview branch has children has siblings closed,qtreeview branch closed has children has siblings qtreeview branch has c...