Setting treeview background color in VB6 has a flaw - help?
Posted
by RenMan
on Stack Overflow
See other posts from Stack Overflow
or by RenMan
Published on 2010-04-27T15:05:45Z
Indexed on
2010/04/27
15:43 UTC
Read the original article
Hit count: 597
I have successfully implemented this method of using the Win32 API to set the background color of a treeview in VB 6: http://support.microsoft.com/kb/178491
However, one thing goes wrong: when you expand the tree nodes more than two levels deep, the area to the left of (and sometimes under) the inner plus [+]
and minus [-]
signs is still white.
Does anyone know how to get this area to the correct background color, too?
Note: I'm also setting the BackColor of each node, and also the BackColor of the treeview's imagelist.
Here's my version of the code:
Public Sub TreeView_SetBackgroundColor(TreeView As MSComctlLib.TreeView, BackgroundColor As Long) Dim lStyle As Long, Node As MSComctlLib.Node For Each Node In TreeView.Nodes Node.BackColor = BackgroundColor Next TreeView.ImageList.BackColor = BackgroundColor Call SendMessage( _ TreeView.hwnd, _ TVM_SETBKCOLOR, _ 0, _ ByVal BackgroundColor) 'Now reset the style so that the tree lines appear properly. lStyle = GetWindowLong(TreeView.hwnd, GWL_STYLE) Call SetWindowLong(TreeView.hwnd, GWL_STYLE, lStyle - TVS_HASLINES) Call SetWindowLong(TreeView.hwnd, GWL_STYLE, lStyle) End Sub
© Stack Overflow or respective owner