Treeview couleur de fond

  • Initiateur de la discussion Initiateur de la discussion abtony
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

abtony

XLDnaute Impliqué
Bonjour le forum, bon week end a tous.

est t'il possible de changer la couleur de fond d'un treeview (blanc par défaut),
par une autre couleur ?

merci a vous
 
Re : Treeview couleur de fond

Bonjour phlaurent55,

cela ne correspond pas a ma demande, il s'agit d'un control treeview dont le backcolor est blanc par défaut, je souhaite changer la couleur mais l'option ne se trouve pas dans les propriété de ce controle.

peut etre pas possible je sait pas, pour ca que je pose la question.

merci quand même pour ton interet !

bonne journée
 
Re : Treeview couleur de fond

bonjour

La procédure proposée par Kiki29 fonctionne parfaitement

Dans un module standard:

Code:
Option Explicit
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
    Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd _
    As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd _
    As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long



Dans le module objet du userform

Code:
Option Explicit
Const GWL_STYLE = -16&
Const TVM_SETBKCOLOR = 4381&
Const TVS_HASLINES = 2&

Private Sub UserForm_Activate()
    SetTreeViewBackColor TreeView1, RGB(255, 0, 0)
End Sub
 
Sub SetTreeViewBackColor(TV As TreeView, ByVal BackColor As Long)
    Dim lStyle As Long
    Dim TVNode As Node
         
    ' set the BackColor for every node
    For Each TVNode In TV.Nodes
        TVNode.BackColor = BackColor
    Next
    ' set the BackColor for the TreeView's window
    SendMessage TV.hwnd, TVM_SETBKCOLOR, 0, ByVal BackColor
    ' get the current style
    lStyle = GetWindowLong(TV.hwnd, GWL_STYLE)
    ' temporary hide lines
    SetWindowLong TV.hwnd, GWL_STYLE, lStyle And (Not TVS_HASLINES)
    ' redraw lines
    SetWindowLong TV.hwnd, GWL_STYLE, lStyle
End Sub



Bonne soirée
MichelXld
 
Re : Treeview couleur de fond

re kiki, bonsoir michelxld,

je n'ai pas été assez douée pour mettre en application l'info a kiki, avec les explications a michelxld il est vrais que ca fonctionne parfaitement.😀

merci beaucoup pour votre aide.

Bonne soirée
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
40
Réponses
7
Affichages
75
Réponses
8
Affichages
68
Retour