Comment faire pour que cette ligne indiquant le répertoire dans ma Treeview reste surligné ?
TreeView1.HideSelection = Falsed'abord puisque c'est celle qui à la coche discussion résolue.
Public Class MonTreeView Inherits TreeView Public Sub New() Me.DrawMode = TreeViewDrawMode.OwnerDrawAll End Sub Protected Overrides Sub OnDrawNode(ByVal e As DrawTreeNodeEventArgs) If e.Node Is e.Node.TreeView.SelectedNode Then Dim foreColor As Color = SystemColors.HighlightText Dim selectedColor As Color = Color.Blue 'couleur avec focus Dim deselectedColor As Color = Color.Gray 'couleur sans le focus Dim treeFont As Font = If(e.Node.NodeFont, e.Node.TreeView.Font) ' New brush. Dim selectedTreeBrush As New SolidBrush(selectedColor) 'brush avec focus Dim deselectedTreeBrush As New SolidBrush(deselectedColor) 'brush sans le focus If Me.Focused Then e.Graphics.FillRectangle(selectedTreeBrush, e.Node.Bounds) Else e.Graphics.FillRectangle(deselectedTreeBrush, e.Node.Bounds) End If ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds, foreColor, SystemColors.Highlight) TextRenderer.DrawText(e.Graphics, e.Node.Text, treeFont, e.Node.Bounds, foreColor, TextFormatFlags.GlyphOverhangPadding) Else e.DrawDefault = True End If End Sub End Class
Private Sub treeView1_NodeMouseClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
e.Node.ForeColor = Color.Blue
e.Node.ForeColor = Color.Black e.Node.BackColor = Color.Blue
#Region "Remove BackColor" Private Sub treeView1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) ClearBackColor() End Sub 'recursively move through the treeview nodes 'and reset backcolors to white Private Sub ClearBackColor() Dim nodes As TreeNodeCollection nodes = TreeView1.Nodes Dim n As TreeNode For Each n In nodes ClearRecursive(n) Next End Sub 'called by ClearBackColor function Private Sub ClearRecursive(ByVal treeNode As TreeNode) Dim tn As TreeNode For Each tn In treeNode.Nodes tn.BackColor = Color.White ClearRecursive(tn) Next End Sub #End Region #Region "Find Node By Name" Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Then Exit Sub ClearBackColor() Try Dim tn() As TreeNode = _ TreeView1.Nodes(0).Nodes.Find(TextBox1.Text, True) Dim i As Integer = 0 For i = 0 To tn.Length TreeView1.SelectedNode = tn(i) TreeView1.SelectedNode.BackColor = Color.Blue Next i Catch 'do nothing End Try End Sub #End Region #Region "Find By Text" Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs) Handles Button2.Click If TextBox1.Text = "" Then Exit Sub ClearBackColor() FindByText() End Sub Private Sub FindByText() Dim nodes As TreeNodeCollection = TreeView1.Nodes Dim n As TreeNode For Each n In nodes FindRecursive(n) Next End Sub Private Sub FindRecursive(ByVal tNode As TreeNode) Dim tn As TreeNode For Each tn In tNode.Nodes ' if the text properties match, color the item If tn.Text = Me.TextBox1.Text Then tn.BackColor = Color.Blue End If FindRecursive(tn) Next End Sub #End Region
11 mai 2017 à 21:06
12 mai 2017 à 06:32
Donc tout code c# une fois passé dans le Skin fonctionne en vb.net