横向大小控制使用: indentation 缩进 缩排 属性。
纵向大小控制使用:图标控制。

解决方案 »

  1.   

    可以通过一些属性来更改,比如Identation,参考一下MSDN中的帮助
      

  2.   

    在MSDN中,纵向好像无法控制。还有,Node文字的前景色和背景色如何调整?
      

  3.   

    而且,添加了image后,identation属性似乎就失效了。
      

  4.   

    用VC++写的自绘treeview就可以自己来控制颜色和字体等
    VB恐怕难度就大了,没有提供现成的函数,不好办哦,呵呵
      

  5.   

    试试吧: tvTreeView.Indentation = 1200改改"1200"这个数看看是否满足你的要求Private Sub Form_Load()
        tvTreeView.Indentation = 1200
    end sub
      

  6.   

    用MSDN提供的例子试过了。
    发现一个规律:如果绑定imagelist,Indentation就无效。
    如果没有绑定,就有效。
      

  7.   

    有没有比TreeView更强大的控件?
      

  8.   

    用APi吧,主要函数:
    sendmessage(TreeView1.hwnd,tv_??/tvm_??,1,1)tv_??/tvm_?? 为:外观参数,命令参数等
      

  9.   

    高手,用哪个API?
    仅sendmessage就够了吗?
      

  10.   

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
      

  11.   

    这样设有用吗? l = SendMessage(TreeView1.hwnd, tvwTreelinesPictureText, 1, "")好像没有什么变化。
      

  12.   

    sonicdater(发呆呆)怎样拦截消息?
      

  13.   

    拦截消息 一时是讲不清楚的
    你最好看看一些关于API的书!
      

  14.   

    (一) 普通的 改变Treeview 背景颜色:lngBackColor = &HE0F8FE ' light yellow color
    Call SendMessage(TV1.hWnd, _
                     TVM_SETBKCOLOR, _
                     0, _
                     ByVal lngBackColor)  (二) 拦截消息, 实现背景颜色渐变.
    实在太复杂了. 用 回调函数.
      

  15.   

    看看这些有用吗?Private Function GetTVBackColour() As Long   Dim clrref As Long
       Dim hwndTV As Long
       
       hwndTV = TreeView1.hwnd
       
      'try for the treeview backcolor
       clrref = SendMessage(hwndTV, TVM_GETBKCOLOR, 0, ByVal 0)
       
      'if clrref = -1, then the color is a system color.
      'In theory, system colors need to be Or'd with &HFFFFFF
      'to retrieve the actual RGB value, but not Or'ing
      'seems to work for me. The default system colour for
      'a treeview background is COLOR_WINDOW.
       If clrref = -1 Then
          clrref = GetSysColor(COLOR_WINDOW)  ' Or &HFFFFFF
       End If
       
      'one way or another, pass it back
       GetTVBackColour = clrref
       
    End Function
    Private Function GetTVForeColour() As Long   Dim clrref As Long
       Dim hwndTV As Long
       
       hwndTV = TreeView1.hwnd
       
      'try for the treeview text colour
       clrref = SendMessage(hwndTV, TVM_GETTEXTCOLOR, 0, ByVal 0)
       
      'if clrref = -1, then the color is a system color.
      'In theory, system colors need to be Or'd with &HFFFFFF
      'to retrieve the actual RGB value, but not Or'ing
      'seems to work for me. The default system colour for
      'treeview text is COLOR_WINDOWTEXT.
       If clrref = -1 Then
          clrref = GetSysColor(COLOR_WINDOWTEXT) ' Or &HFFFFFF
       End If
       
      'one way or another, pass it back
       GetTVForeColour = clrref
       
    End Function
    Private Sub SetTVBackColour(clrref As Long)   Dim hwndTV As Long
       Dim style As Long
       
       hwndTV = TreeView1.hwnd
       
      'Change the background
       Call SendMessage(hwndTV, TVM_SETBKCOLOR, 0, ByVal clrref)
       
      'reset the treeview style so the
      'tree lines appear properly
       style = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
       
      'if the treeview has lines, temporarily
      'remove them so the back repaints to the
      'selected colour, then restore
       If style And TVS_HASLINES Then
          Call SetWindowLong(hwndTV, GWL_STYLE, style Xor TVS_HASLINES)
          Call SetWindowLong(hwndTV, GWL_STYLE, style)
       End If
      
    End Sub
    Private Sub SetTVForeColour(clrref As Long)   Dim hwndTV As Long
       Dim style As Long
       
       hwndTV = TreeView1.hwnd
       
      'Change the background
       Call SendMessage(hwndTV, TVM_SETTEXTCOLOR, 0, ByVal clrref)
       
      'reset the treeview style so the
      'tree lines appear properly
       style = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
       
      'if the treeview has lines, temporarily
      'remove them so the back repaints to the
      'selected colour, then restore
       If style And TVS_HASLINES Then
          Call SetWindowLong(hwndTV, GWL_STYLE, style Xor TVS_HASLINES)
          Call SetWindowLong(hwndTV, GWL_STYLE, style)
       End If
       
    End Sub
    Private Sub cmdSetBackground_Click()'按钮单击   Dim newclr As Long
       
       With cDlg
          .Flags = cdlCCRGBInit      'using RGB colours
          .Color = GetTVBackColour() 'pre-select the current colour
          .ShowColor                 'get the user's choice
          newclr = .Color            'and assign to a var
       End With
       
       SetTVBackColour newclr        'set the backcolour
       
    End Sub
    Private Sub cmdBold_Click()'按钮单击   Dim TVI As TV_ITEM
       Dim hitemTV As Long
       Dim hwndTV As Long
       
      'get the handle to the treeview item.
      'If the item is selected, use TVGN_CARET.
      'To highlight the first item in the root, use TVGN_ROOT
      'To hilight the first visible, use TVGN_FIRSTVISIBLE
      'To hilight the selected item, use TVGN_CARET
       hwndTV = TreeView1.hwnd
       hitemTV = SendMessage(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0&)
       
      'if a valid handle get and set the
      'item's state attributes
       If hitemTV > 0 Then
       
          With TVI
             .hItem = hitemTV
             .mask = TVIF_STATE
             .stateMask = TVIS_BOLD
              Call SendMessage(hwndTV, TVM_GETITEM, 0&, TVI)
             
             'flip the bold mask state
             .state = TVIS_BOLD
          End With
          
          Call SendMessage(hwndTV, TVM_SETITEM, 0&, TVI)
     
       End If
       
    End Sub
    Private Sub cmdFullRow_Click()'按钮单击   Dim hwndTV As Long
       Dim style As Long  'get the window style
       style = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
       
      'toggle the fullrow select
       If style And TVS_FULLROWSELECT Then
             style = style Xor TVS_FULLROWSELECT
       Else: style = style Or TVS_FULLROWSELECT
       End If
       
      'and set it
       Call SetWindowLong(TreeView1.hwnd, GWL_STYLE, style)
       
    End Sub
    Private Sub cmdSetText_Click()'按钮单击   Dim newclr As Long
       
       With cDlg
          .Flags = cdlCCRGBInit      'using RGB colours
          .Color = GetTVForeColour() 'pre-select the current colour
          .ShowColor                 'get the user's choice
          newclr = .Color            'and assign to a var
       End With
       
       SetTVForeColour newclr        'set the text colour
       
    End Sub并在模块中加入下面的内容:Option Explicit
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Copyright ?996-2000 VBnet, Randy Birch, All Rights Reserved.
    ' Some pages may also contain other copyrights by the author.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' You are free to use this code within your own applications,
    ' but you are expressly forbidden from selling or otherwise
    ' distributing this source code without prior written consent.
    ' This includes both posting free demo projects made from this
    ' code as well as reproducing the code in text or html format.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Const GWL_STYLE As Long = (-16)
    Public Const COLOR_WINDOW As Long = 5
    Public Const COLOR_WINDOWTEXT As Long = 8Public Const TVI_ROOT   As Long = &HFFFF0000
    Public Const TVI_FIRST  As Long = &HFFFF0001
    Public Const TVI_LAST   As Long = &HFFFF0002
    Public Const TVI_SORT   As Long = &HFFFF0003Public Const TVIF_STATE As Long = &H8'treeview styles
    Public Const TVS_HASLINES As Long = 2
    Public Const TVS_FULLROWSELECT As Long = &H1000'treeview style item states
    Public Const TVIS_BOLD  As Long = &H10Public Const TV_FIRST As Long = &H1100
    Public Const TVM_GETNEXTITEM As Long = (TV_FIRST + 10)
    Public Const TVM_GETITEM As Long = (TV_FIRST + 12)
    Public Const TVM_SETITEM As Long = (TV_FIRST + 13)
    Public Const TVM_SETBKCOLOR As Long = (TV_FIRST + 29)
    Public Const TVM_SETTEXTCOLOR As Long = (TV_FIRST + 30)
    Public Const TVM_GETBKCOLOR As Long = (TV_FIRST + 31)
    Public Const TVM_GETTEXTCOLOR As Long = (TV_FIRST + 32)Public Const TVGN_ROOT                As Long = &H0
    Public Const TVGN_NEXT                As Long = &H1
    Public Const TVGN_PREVIOUS            As Long = &H2
    Public Const TVGN_PARENT              As Long = &H3
    Public Const TVGN_CHILD               As Long = &H4
    Public Const TVGN_FIRSTVISIBLE        As Long = &H5
    Public Const TVGN_NEXTVISIBLE         As Long = &H6
    Public Const TVGN_PREVIOUSVISIBLE     As Long = &H7
    Public Const TVGN_DROPHILITE          As Long = &H8
    Public Const TVGN_CARET               As Long = &H9Public Type TV_ITEM
       mask As Long
       hItem As Long
       state As Long
       stateMask As Long
       pszText As String
       cchTextMax As Long
       iImage As Long
       iSelectedImage As Long
       cChildren As Long
       lParam As Long
    End TypePublic Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
       (ByVal hwnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        lParam As Any) As LongPublic Declare Function GetWindowLong Lib "user32" _
       Alias "GetWindowLongA" _
       (ByVal hwnd As Long, _
        ByVal nIndex As Long) As LongPublic Declare Function SetWindowLong Lib "user32" _
       Alias "SetWindowLongA" _
       (ByVal hwnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As LongPublic Declare Function GetSysColor Lib "user32" _
       (ByVal nIndex As Long) As Long
      

  16.   

    http://www.dapha.net/soure/pic/Treeview%20with%20background%20picture.zip
    代码名称 有背景图片的Treeview  
    代码类型 图形图像 
    运行环境 Win9x/WinNT/Win2000/WinME 
    授权方式 共享软件 
    代码大小 13K 
    代码评价  
    上传时间 2001-12-14 
    相关链接 主页 
    本日下载 1  本周:21  总计:21 
    下载地址1 下载 
    代码简介 有背景图片的Treeview.
      

  17.   

    可以不可以这样:1 用VC++做一个CTreeView控件,供VB调用。
    2 直接使用VB.net的TreeView控件。
    3 用VB自己做一个ActiveX控件。
      

  18.   

    好象大家都不太喜欢用API啊,单SENDMESSAGE,就可以实现很多控件的功能啦。
    比如 :
    sendmessage(windows1.hwnd,wm_??,pram1,pram2)sendmessage(list1.hwnd,lb_??,pram1,pram2)
    sendmessage(combox1.hwnd,mb_??,pram1,pram2)
    sendmessage(text1.hwnd,eb_??,pram1,pram2) 还有好多,多看看API VIEW里的常数定义吧,一定不会让你失望。
      

  19.   

    能举个例子吗?
    去哪里看API?
      

  20.   

    to rushing:1 用VC++派生一个CPowerTreeView控件,供VB调用。这个方案是可行的,VC代码都有的...to xiaohuangtao(绿毛网虫) :
    你那个就叫使用API吗?若是别人的控件不提供该消息响应接口,恐怕你也无能为力吧
      

  21.   

    gameboy999(我心迷茫) CTreeView基类可以找到。
    但是,CPowerTreeView好像没有吧。
      

  22.   

    其实,如果想让VB做太多的事,的确很勉为其难,微软设计它并不想让它做那麽多的事情,为什么不试试Delphi?为什么要永远站在微软的屋檐下呢?
      

  23.   

    对了~
    顺便问一下,给TREEVIEW发消息用的声明常量的值上哪里找?好像API 文本浏览器中没有啊~
    还有怎么给TREEVIEW发TVM_EXPAND消息?SendMessage的第二个参数lParam应该是谁?比如说我想展开TREEVIEW的ROOT的child。我看了一下午MSDN也没看懂~
    555555555……
      

  24.   

    to rivershan:
    到VC得头文件中去找吧。
    include\comctl.h
      

  25.   

    luoxiangdong(罗向东)可是我的程序就差这一点了啊。
    能用Delphi做个功能强大的TreeView.ocx控件,让VB来用吗?
      

  26.   

    最后我决定自己做一个TreeView控件。
    现在已经做好了一部分。
    可以增加图片,调整竖线和横线位置,属性添加Child。
    但是,Node功能还没有,imagelist也不太好用。