zoukankan      html  css  js  c++  java
  • VB中如何修改treeview的背景色

    改变 TreeView 的背景   
     
    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))
    '改变背景到红色

    lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
    Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
    Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
    End Sub

    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&

    Private Sub Form_Load()

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

    Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
    lStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
    Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lStyle - TVS_HASLINES)
    Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lStyle)

    TreeView1.Style = tvwTreelinesPlusMinusPictureText
    TreeView1.BorderStyle = ccFixedSingle
    With TreeView1.Nodes
    Set nodex = .Add(, , "R", "Root")
    nodex.BackColor = RGB(255, 0, 0)
    For i = 1 To 10
        Set nodex = .Add("R", tvwChild, "C" & i, "Child " & i)
        nodex.BackColor = RGB(255, 0, 0)
        nodex.EnsureVisible
    Next
    End With

    End Sub

  • 相关阅读:
    Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
    Educational Codeforces Round 33 (Rated for Div. 2) A. Chess For Three【模拟/逻辑推理】
    java中的BigInteger
    动态规划-最长上升子序列(LIS模板)多解+变形
    Rain on your Parade---hdu2389(HK求最大匹配)
    Air Raid---hdu1151(最小路径覆盖)
    Swap---hdu2819(最大匹配)
    棋盘游戏---hdu1281(最大匹配)
    The Accomodation of Students---hdu2444(二分图,最大匹配)
    COURSES---poj1469 hdu1083(最大匹配)
  • 原文地址:https://www.cnblogs.com/rosesmall/p/3359406.html
Copyright © 2011-2022 走看看