2011-12-09 4 views
1

아래 코드와 같은 모든 모드를 그릴 때 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 

이 트리 뷰를 그립니다 내가 원하는대로 정확하게 그러나 어떤 이유로 원자바오 텍스트가 굵게 보이는 원인 노드가 다시 그려 얻을 것 열림/닫힘 요소를하지만, 마지막으로 다시 그리기의 맨 위에 마우스를하고 어떤 이미지 주위의 개요. 그러나 노드가 선택되지 않은 경우에만이 옵션이 선택되면 모든 것이 정상입니다. 죄송합니다. 새 사용자가 화면 덤프를 게시 할 수 없습니다.

마우스 오버 글리프 이벤트에 연결하여 그리기 이벤트에서 보낸 사람을 감지 할 수 있지만 이제는 이상적인 메시지를 보내지 않도록 제어 할 수 있는지 확실하지 않습니다.

는 시도 : 그래픽을 지우기

  • 는 무승부 개체 노드에게
  • 설정 배경 사각형 그리기와 노드를 그리기 전에
+0

당신은 배경을 그려서 전체 e.Bounds를 채우십시오. –

답변

1

당신이 '나오지 않았어 이후는 정말 추측 할 수를 선택 할 때처럼 이미지를 게시하지 마십시오. 포함 된 코드가 완전하지 않습니다 (ActioNode? AssertionNode?).

내가 배경을 지우는 데 언급했는데 게시 한 코드가 노드 영역을 비우지 않았 음을 알고 있습니다.

Dim rect As New Rectangle(0, e.Bounds.Top, Me.ClientSize.Width - 1, e.Bounds.Height - 1) 
If e.State And TreeNodeStates.Selected Then 
    e.Graphics.FillRectangle(Brushes.AliceBlue, rect) 
    e.Graphics.DrawRectangle(Pens.DarkSlateBlue, rect) 
Else 
    e.Graphics.FillRectangle(SystemBrushes.Window, rect) 
End If 

를 왜 모든 예외를 무시하고 있습니다 : 그것은 작동하는 경우이 같은로 변경 시도를 참조하십시오?

또한 글꼴을 처리해야합니다.

+0

안녕하세요. 그래픽 오브젝트를 지우는 데 아무런 영향도없는 것 같아서요. 왜 내가 그걸 유일한 이유라고 생각하는지 모르겠군요. 제대로 작동하는 것으로 보이는 선택된 노드와 다른 코드 비트. 나는 모든 예외를 무시하지 않고 방금 그 예외를 던져 더 자세한 정보를 얻었습니다. 인스턴트 메신저 그냥 실제 treeview 글꼴을 사용하여 그것을 처분 할 필요는 알지 못했지만 지금은 감사합니다. 궁극적 인 행동/주장 노드와 혼란에 대해 유감스럽게 생각합니다. 노드를 그리는 데 필요한 일부 데이터를 추가하기 위해 treenode를 상속하는 클래스입니다. –