熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VB中如何修改treeview的背景色

2022-06-13   來源: .NET編程 
改變 TreeView 的背景  
 
Private Declare Function SendMessage Lib User Alias SendMessageA (ByVal hWnd As Long ByVal wMsg As Long ByVal wParam

  As Long lParam As Long) As Long

  Private Declare Function GetWindowLong Lib User Alias GetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long) As Long

  Private Declare Function SetWindowLong Lib User Alias SetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long ByVal

  dwNewLong As Long) As Long

  Private Const GWL_STYLE = &
Private Const TVM_SETBKCOLOR = &
Private Const TVM_GETBKCOLOR = &
Private Const TVS_HASLINES = &

  Dim frmlastForm As Form

  Private Sub Form_Load()
Dim nodX As Node
Set nodX = TreeViewNodesAdd( R Root)
Set nodX = TreeViewNodesAdd(R tvwChild C Child )
Set nodX = TreeViewNodesAdd(R tvwChild C Child )
Set nodX = TreeViewNodesAdd(R tvwChild C Child )
Set nodX = TreeViewNodesAdd(R tvwChild C Child )
nodXEnsureVisible
TreeViewstyle = tvwTreelinesText Style
TreeViewBorderStyle = vbFixedSingle
End Sub

  Private Sub Command_Click()
Dim lngStyle As Long
Call SendMessage(TreeViewhWnd TVM_SETBKCOLOR ByVal RGB( ))
改變背景到紅色

  lngStyle = GetWindowLong(TreeViewhWnd GWL_STYLE)
Call SetWindowLong(TreeViewhWnd GWL_STYLE lngStyle TVS_HASLINES)
Call SetWindowLong(TreeViewhWnd GWL_STYLE lngStyle)
End Sub

  Option Explicit

  Private Declare Function SendMessage Lib User Alias SendMessageA (ByVal hWnd As Long ByVal wMsg As Long ByVal wParam As Long lParam As Long) As Long
Private Declare Function GetWindowLong Lib User Alias GetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib User Alias SetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long ByVal dwNewLong As Long) As Long

  Private Const GWL_STYLE = &
Private Const TVM_SETBKCOLOR = &
Private Const TVM_GETBKCOLOR = &
Private Const TVS_HASLINES = &

  Private Sub Form_Load()

  Dim nodex As Node
Dim i As Integer
Dim lStyle As Long

  Call SendMessage(TreeViewhWnd TVM_SETBKCOLOR ByVal RGB( ))
lStyle = GetWindowLong(TreeViewhWnd GWL_STYLE)
Call SetWindowLong(TreeViewhWnd GWL_STYLE lStyle TVS_HASLINES)
Call SetWindowLong(TreeViewhWnd GWL_STYLE lStyle)

  TreeViewStyle = tvwTreelinesPlusMinusPictureText
TreeViewBorderStyle = ccFixedSingle
With TreeViewNodes
Set nodex = Add( R Root)
nodexBackColor = RGB( )
For i = To
    Set nodex = Add(R tvwChild C & i Child & i)
    nodexBackColor = RGB( )
    nodexEnsureVisible
Next
End With

  End Sub
From:http://tw.wingwit.com/Article/program/net/201311/12961.html

  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.