[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1437
  • Last Modified:

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.
Regards
Terry
0
TerenceHewett
Asked:
TerenceHewett
  • 2
1 Solution
 
tbsgadiCommented:
Have a look at the following:
http://www.bigresource.com/Tracker/Track-vb-ef9ze52rMw/


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

Regards
Terry
0
 
tbsgadiCommented:
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")
          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))  '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

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now