Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Tips & tricks

#229 - Gör special effekter på en Treeview via API

Postat 2000-12-22 15:14:47 av Pelle Johansson i Kategori Programmering, C#, Kommandon med 0 Kommentarer

Option Explicit
Private Sub Form_Load()
Dim nodX As Node

'addera några testrader
Set nodX = TV1.Nodes.Add(, , "R", "Root")
Set nodX = TV1.Nodes.Add("R", tvwChild, "C1", "Child 1")
Set nodX = TV1.Nodes.Add("R", tvwChild, "C2", "Child 2")
Set nodX = TV1.Nodes.Add("R", tvwChild, "C3", "Child 3")
Set nodX = TV1.Nodes.Add("R", tvwChild, "C4", "Child 4")
nodX.EnsureVisible

Set nodX = TV1.Nodes.Add("C3", tvwChild, "C31", "Child 3 SubC 1")
Set nodX = TV1.Nodes.Add("C3", tvwChild, "C32", "Child 3 SubC 2")
nodX.EnsureVisible

Set nodX = TV1.Nodes.Add("C31", tvwChild, "C321", "Child 3 SubC 1 SubC 1")
Set nodX = TV1.Nodes.Add("C4", tvwChild, "C41", "Child 4 Subchild 1")
nodX.EnsureVisible
End Sub

Private Sub cmdEnd_Click()
Unload Me
End Sub

Private Function GetTVBackColour() As Long
Dim clrref As Long
Dim hwndTV As Long
hwndTV = TV1.hwnd

'försök hämta treeview bakgrundsfärg
clrref = SendMessageLong(hwndTV, TVM_GETBKCOLOR, 0, 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

'Skicka tillbaks resultatet
GetTVBackColour = clrref
End Function

Private Function GetTVForeColour() As Long

Dim clrref As Long
Dim hwndTV As Long
hwndTV = TV1.hwnd

'try for the treeview text colour
clrref = SendMessageLong(hwndTV, TVM_GETTEXTCOLOR, 0, 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 = TV1.hwnd

'Change the background
Call SendMessageLong(hwndTV, TVM_SETBKCOLOR, 0, clrref)

'reset the treeview style so the
'tree lines appear properly
style = GetWindowLong(TV1.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)
Dim hwndTV As Long
Dim style As Long
hwndTV = TV1.hwnd

'Change the background
Call SendMessageLong(hwndTV, TVM_SETTEXTCOLOR, 0, clrref)

'reset the treeview style so the
'tree lines appear properly
style = GetWindowLong(TV1.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 TVITEM
Dim r As Long
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 = TV1.hwnd
hitemTV = SendMessageLong(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 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
r = SendMessageAny(hwndTV, TVM_GETITEM, 0&, TVI)
'flip the bold mask state
.state = TVIS_BOLD
End With
r = SendMessageAny(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(TV1.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(TV1.hwnd, GWL_STYLE, style)

End Sub


Private Sub cmdSetText_Click()
Dim newclr As Long
With cDlg
.Flags = cdlCCRGBInit 'använd rgb colours
.Color = GetTVForeColour() 'förselektera aktuell colour
.ShowColor 'Användaren får bestämma färg
newclr = .Color 'addera till parameter
End With
SetTVForeColour newclr 'sätt text färgen
End Sub

Sample:
Size:

Nyligen

  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo
  • 14:25 Tips på verktyg för att skapa QR-k
  • 14:23 Tips på verktyg för att skapa QR-k
  • 20:52 Fungerer innskuddsbonuser egentlig

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 159
27 952
271 704
951
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies