아래 코드와 같은 모든 모드를 그릴 때 treeview의 노드 그리기 이벤트를 오버라이드하고 있습니다.마우스 오버 축소/확장 글리프에서 사용자 정의 treeview 그리기 버그
Protected Overrides Sub OnDrawNode(ByVal e As System.Windows.Forms.DrawTreeNodeEventArgs)
Try
Dim Indent = e.Node.Level * Me.Indent + 32
Dim font = Me.Font
'draw selected
If e.State And TreeNodeStates.Selected Then
Dim rect As New Rectangle(0, e.Bounds.Location.Y, Me.Width - 1, e.Bounds.Height - 1)
e.Graphics.FillRectangle(Brushes.AliceBlue, rect)
e.Graphics.DrawRectangle(Pens.DarkSlateBlue, rect)
End If
'draw status icon
e.Graphics.DrawImage(Me.ImageList.Images(e.Node.ImageIndex), New Point(e.Bounds.X + indent - Me.ImageList.ImageSize.Width + 2, e.Bounds.Y + ((Me.ItemHeight/2) - (Me.ImageList.ImageSize.Height/2))))
'draw collapse glyph
If e.Node.Nodes.Count > 0 Then
Dim element As VisualStyleElement
Dim glyphRect = New Rectangle(e.Bounds.Location.X + 2 + e.Node.Level * Me.Indent, e.Bounds.Location.Y + 8, 16, 16)
If e.Node.IsExpanded Then
element = VisualStyleElement.TreeView.Glyph.Opened
Else
element = VisualStyleElement.TreeView.Glyph.Closed
End If
Dim renderer As New VisualStyleRenderer(element)
renderer.DrawBackground(e.Graphics, glyphRect)
End If
If e.Node.Level.Equals(0) Then
font = New Font(Me.Font.Name, 12, FontStyle.Regular)
e.Graphics.DrawString(e.Node.Text, font, Brushes.MidnightBlue, New Point(indent + 5, e.Bounds.Location.Y + 5), New StringFormat())
ElseIf e.Node.Level.Equals(1) Then
'action
Dim params = CType(e.Node, ActionNode).Params
Dim x = indent + 5
e.Graphics.DrawString(e.Node.Text, Me.Font, Brushes.Black, New Point(x, e.Bounds.Location.Y + 2), New StringFormat())
For Each param In params
e.Graphics.DrawString(param.Key & ":", Me.Font, Brushes.DarkSlateBlue, New Point(x, e.Node.Bounds.Location.Y + 15))
x += e.Graphics.MeasureString(param.Key & ":", Me.Font).Width - 1
e.Graphics.DrawString(param.Value, Me.Font, Brushes.SlateGray, New Point(x, e.Node.Bounds.Location.Y + 15))
x += e.Graphics.MeasureString(param.Value, Me.Font).Width
Next
ElseIf e.Node.Level.Equals(2) Then
'assertion
Dim params = CType(e.Node, AssertionNode).Params
Dim x = indent + 5
e.Graphics.DrawString(e.Node.Text, Me.Font, Brushes.Black, New Point(x, e.Bounds.Location.Y + 2), New StringFormat())
For Each param In params
e.Graphics.DrawString(param.Key & ":", Me.Font, Brushes.DarkSlateBlue, New Point(x, e.Node.Bounds.Location.Y + 15))
x += e.Graphics.MeasureString(param.Key & ":", Me.Font).Width - 1
e.Graphics.DrawString(param.Value, Me.Font, Brushes.SlateGray, New Point(x, e.Node.Bounds.Location.Y + 15))
x += e.Graphics.MeasureString(param.Value, Me.Font).Width
Next
End If
Catch ex As Exception
End Try
End Sub
이 트리 뷰를 그립니다 내가 원하는대로 정확하게 그러나 어떤 이유로 원자바오 텍스트가 굵게 보이는 원인 노드가 다시 그려 얻을 것 열림/닫힘 요소를하지만, 마지막으로 다시 그리기의 맨 위에 마우스를하고 어떤 이미지 주위의 개요. 그러나 노드가 선택되지 않은 경우에만이 옵션이 선택되면 모든 것이 정상입니다. 죄송합니다. 새 사용자가 화면 덤프를 게시 할 수 없습니다.
마우스 오버 글리프 이벤트에 연결하여 그리기 이벤트에서 보낸 사람을 감지 할 수 있지만 이제는 이상적인 메시지를 보내지 않도록 제어 할 수 있는지 확실하지 않습니다.
는 시도 : 그래픽을 지우기
- 는 무승부 개체 노드에게
- 설정 배경 사각형 그리기와 노드를 그리기 전에
당신은 배경을 그려서 전체 e.Bounds를 채우십시오. –