Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleChange a TreeView control's background color
Description
KeywordsTreeView, background, background color, backcolor
CategoriesControls, Graphics, API
 
Use the SendMessage API function to send the control the TVM_SETBKCOLOR message. Then reset a few style bits needed by the TreeView control.
 
Private Sub ChangeBackgroundColor(ByVal hWnd As Long, ByVal _
    longColor As Long)
Dim longStyle As Long

    SendMessage hWnd, TVM_SETBKCOLOR, 0, ByVal _
        TranslateColor(longColor)

    ' Reset style so lines display properly (for TreeView
    ' control only)
    longStyle = GetWindowLong(hWnd, GWL_STYLE)
    SetWindowLong hWnd, GWL_STYLE, _
        longStyle And (Not TVS_HASLINES)
    SetWindowLong hWnd, GWL_STYLE, longStyle
End Sub
 
Jen Keller explains that this works with version 5 of the TreeView control but with version 6 the control blocks around the TreeView's text keeps the old background color.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated