28/10/21 19:00
Carlo
qualsiasi colore scegli per la selezione, comunque ti dovrai scontrare con la scelta dei colori che siano ben visibili sia con il selezionato che senza
così ti piace?
il font per la treeview da progettazione ho usato: Century Gothic, normale, 10
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TVAtt.DrawMode = TreeViewDrawMode.OwnerDrawText
AddHandler TVAtt.DrawNode, AddressOf TVAtt_drawNode
TVAtt.BackColor = Color.FromArgb(64, 64, 64)
TVAtt.LineColor = Color.White
End Sub
Private Sub TVAtt_drawNode(sender As Object, e As DrawTreeNodeEventArgs)
Dim g As Graphics = e.Graphics
Dim colore1 As Brush = Brushes.White
Dim colore2 As Brush = Brushes.White
Dim linea = e.Node.Text.Split(";"c)
Dim Size As SizeF
e.Node.BackColor = Color.Black
If e.Node.Bounds.X = 0 Then Exit Sub
If linea.GetUpperBound(0) > 1 Then
Select Case linea(2).ToLower().Trim()
Case "red"
colore1 = Brushes.Red
Case "gray"
colore1 = Brushes.Gray
Case "green"
colore1 = Brushes.LightGreen
Case "blue"
colore1 = Brushes.RoyalBlue
Case "yellow"
colore1 = Brushes.Gold
Case "cyan"
colore1 = Brushes.Cyan
Case "black"
colore1 = Brushes.Black
Case "orange"
colore1 = Brushes.Orange
Case Else
colore1 = Brushes.White
End Select
If linea.GetUpperBound(0) > 2 AndAlso linea(3).ToLower.Trim = "true" Then
Size = g.MeasureString(linea(0), New Font(TVAtt.Font, FontStyle.Bold))
g.DrawString(linea(0), New Font(TVAtt.Font, FontStyle.Bold), colore1, e.Node.Bounds)
Else
Size = g.MeasureString(linea(0), TVAtt.Font)
g.DrawString(linea(0), TVAtt.Font, colore1, e.Node.Bounds)
End If
End If
If linea.GetUpperBound(0) > 3 Then
Select Case linea(4).ToLower().Trim()
Case "red"
colore2 = Brushes.Red
Case "gray"
colore2 = Brushes.Gray
Case "green"
colore2 = Brushes.LightGreen
Case "blue"
colore2 = Brushes.RoyalBlue
Case "yellow"
colore2 = Brushes.Gold
Case "cyan"
colore2 = Brushes.Cyan
Case "black"
colore2 = Brushes.Black
Case "orange"
colore2 = Brushes.Orange
Case Else
colore2 = Brushes.White
End Select
If linea.GetUpperBound(0) > 4 AndAlso linea(5).ToLower.Trim = "true" Then
g.DrawString(linea(1), New Font(TVAtt.Font, FontStyle.Bold), colore2, e.Node.Bounds.X + Size.Width + 2, e.Node.Bounds.Y)
Else
g.DrawString(linea(1), TVAtt.Font, colore2, e.Node.Bounds.X + Size.Width + 2, e.Node.Bounds.Y)
End If
End If
If linea(0) <> "" And linea.GetUpperBound(0) = 0 Then
g.DrawString(linea(0), TVAtt.Font, colore1, e.Node.Bounds.X, e.Node.Bounds.Y)
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim treeNode1 As New TreeNode("PrimoNodo ")
treeNode1.Nodes.Add(" testo1Arancio;testo2Giallo;orange;true;yellow;true")
treeNode1.Nodes.Add(" testo1Rosso;testo2Blue;red;false;blue;true")
treeNode1.Nodes.Add(" testo1Bianco;testo2Grigio;white;true;gray;false")
TVAtt.Nodes.Add(treeNode1)
Dim treeNode2 As New TreeNode("SecondoNodo ")
treeNode2.Nodes.Add(" testo1Verde;testo2Giallo;green;false;yellow;false")
treeNode2.Nodes.Add(" testo1Rosso;testo2Blue;red;true;blue;false")
treeNode2.Nodes.Add(" testo1Nero;testo2Grigio;black;false;gray;true")
TVAtt.Nodes.Add(treeNode2)
TVAtt.Nodes.Add(" testoStandard")
TVAtt.Nodes.Add(" testoStandard")
Dim treeNode3 As New TreeNode("TerzoNodo ")
treeNode3.Nodes.Add(" Testo;123; green;false; red")
treeNode3.Nodes.Add(" Testo;456; green;false; red;True")
treeNode3.Nodes.Add(" Testo;789; green;false; red;True")
Dim treeNode4 As New TreeNode("QuartoNodo ")
treeNode4.Nodes.Add(" testo1Verde;testo2Giallo;green;true;yellow;true")
treeNode4.Nodes.Add(" testo1Rosso;testo2Nero;red;false;black;true")
treeNode4.Nodes.Add(" testo1Bianco;testo2Arancio;white;true;orange;false")
treeNode3.Nodes.Add(treeNode4)
TVAtt.Nodes.Add(treeNode3)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TVAtt.Nodes.Count > 2 Then
TVAtt.Nodes.Item(3).Text = " TV scadenza;-123-;cyan;false;red;true"
End If
End Sub
End Class
naturalmente si può anche intercettare la selezione e cambiare i colori del testo selezionato
Ultima modifica effettuata da Carlo 28/10/21 19:56
in programmazione tutto è permesso