Changing backcolor and forecolor of TreeView control 6.0 (SP6)

Hi experts,

I have an ActiveX Microsoft TreeView6.0(SP6) control on my form.  The ActiveX control is working well, but I would like to change the background color and forecolor to match the rest of the forms background color.  

Can anybody help?

Thank you.
Who is Participating?
Have a look at the following:

TerenceHewettAuthor Commented:
Thanks for your help Gary.  This info was very useful.

Glad to help:
Here's the code
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&

      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")
          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))  'Change the background
                                                  'color to red.

      ' Now reset the style so that the tree lines appear properly
         lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
         Call SetWindowLong(TreeView1.hWnd, _
                           GWL_STYLE, _
                           lngStyle - TVS_HASLINES)
         Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
      End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.