Results 1 to 2 of 2

Thread: How can I change a treeview background color?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Posts
    18

    How can I change a treeview background color?

    Does anybody know a way to change a treeview bak color?
    Thanks in advance!

  2. #2
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Here is how to do it.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width