欢迎光临
我们一直在努力

VB中如何修改treeview的背景色-.NET教程,VB.Net语言

建站超值云服务器,限时71元/月

改变 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 = tvwtreelinesplusminuspicturetext
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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » VB中如何修改treeview的背景色-.NET教程,VB.Net语言
分享到: 更多 (0)