谢谢!

解决方案 »

  1.   

    加背景图的,代码很长,我就不粘贴了:
    http://www.china-askpro.com/msg33/qa45.shtml改变背景色就比较简单:
    窗体上一个按钮,一个treeview:
    Option ExplicitPrivate Declare Function SendMessage Lib "User32" _
       Alias "SendMessageA" _
       (ByVal hWnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lParam As Long) As LongPrivate Declare Function GetWindowLong Lib "User32" _
       Alias "GetWindowLongA" _
       (ByVal hWnd As Long, _
       ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "User32" _
       Alias "SetWindowLongA" _
       (ByVal hWnd As Long, _
       ByVal nIndex As Long, _
       ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = -16&
    Private Const TVM_SETBKCOLOR = 4381&
    Private Const TVM_GETBKCOLOR = 4383&
    Private Const TVS_HASLINES = 2&Dim frmlastForm As FormPrivate 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 SubPrivate 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
      

  2.   

    Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As LongPrivate Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = -16&Private Const TVM_SETBKCOLOR = 4381&Private Const TVM_GETBKCOLOR = 4383&Private Const TVS_HASLINES = 2&Dim frmlastForm As FormPrivate Sub Form_Load()Dim nodX As NodeSet 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.EnsureVisibleTreeView1.style = tvwTreelinesText ' Style 4.TreeView1.BorderStyle = vbFixedSingleEnd SubPrivate Sub Command1_Click()Dim lngStyle As LongCall SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))'改变背景到红色lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)End Sub