2017-03-11 8 views
2

대상 소프트웨어를 개발 중이며 드로어 링과 원으로 숫자를 사용하여 그림 상자에서 샷을 추적해야합니다. 내 서클에서 그린 모든 서클은 이전 서클의 모든 숫자가 동일하게 업데이트됩니다. 즉, 4 개의 서클 모두에 '4'가 있고, 다른 서클을 그리고 모두 5로 업데이트됩니다.드로잉 서클에서 텍스트 증가 (목록)

내가 이미지와 내 코드 첨부 : 여기 enter image description here

코드입니다 :

Public Class TargetAnalysis 
Dim n As Integer = 0 
Dim zoomPct As Decimal = 1 

Dim shotList As New List(Of Point) 
Dim scaleList As New List(Of Point) 
Dim poaList As New List(Of Point) 
Dim ShotCount As New List(Of Point) 

Private Sub mPictureBox_MouseClick(sender As Object, e As MouseEventArgs) Handles mPictureBox.MouseClick 
    If e.Button = MouseButtons.Left Then 

     If shotFlag = True Then 
      n += 1 
      _shotX = e.X 
      _shotY = e.Y 


      shotList.Add(New Point(_shotX, _shotY)) 
      ShotCount.Add(New Point(_shotX, _shotY)) 

      shotDist = Math.Sqrt((_shotX - _poaX)^2 + (_shotY - _poaY)^2) 
      Me.lbDataPoints.Items.Insert(shotList.Count - 1, "SHOT - " & 
       FormatNumber(shotDist * pLineDist(), 2) & " in.") 
      Me.txtShotCount.EditValue = shotList.Count 

      mPictureBox.Refresh() 

     End If 
    end if 
End Sub 

Private Sub mPictureBox_Paint(sender As Object, e As PaintEventArgs) Handles mPictureBox.Paint 


    'SHOT number 
    For Each s As Point In ShotCount 
     Dim calRad As Decimal = cboCaliber.EditValue/pLineDist()/2 

     Dim _shot As New ShotCount(e.Graphics, New Point(s.X + calRad, s.Y + calRad), cboCaliber.EditValue/pLineDist()/2, 
            "Consolas", FormatNumber((Math.Sqrt((s.X - _poaX)^2 + (s.Y - _poaY)^2)) * 
            pLineDist(), 2) & "in") 
    Next 

end sub 

이 코드가 증가하지 않지만, 쇼를 수행하고 거리

+0

에게 지속 글 머리 기호는 클래스 여야합니다. 그런 다음 각 글 머리 기호를'List (Of T)'에 저장하십시오. 그들이 움직이면서 위치를 업데이트하면 정확한 위치에 각 글 머리 기호를 그립니다. 그들이 작업 영역을 떠날 때 목록에서 삭제하십시오. – OneFineDay

+0

각 글 머리 기호는 클래스에 있습니다. 텍스트 문자열을 자체 클래스로 옮기는 것도 말하고 있습니까? 감사합니다 –

+0

Text를 처리하기 위해 BulletNo 클래스를 추가했는데 이제는 다음과 같이 호출합니다 : For Each t As Integer in _shotNo Dim_shot as New BulletNo (e.Graphics, _shotX, _shotY, n, "Consolas") 다음. 이것은 카운트를 보여 주지만 다른 샷 텍스트 문자열은 삭제합니다. –

답변

0
Public Class TargetAnalysis 

    Dim shotList As New List(Of Point) 
    Dim shotFlag As Boolean 

    Private Function ShotDistance(ByVal shot As Point) As Double 
     ' _poaX and _poaY are the origin? 
     Return Math.Sqrt((shot.X - _poaX)^2 + (shot.Y - _poaY)^2) * pLineDist() 
    End Function 

    Private Sub mPictureBox_MouseClick(sender As Object, e As MouseEventArgs) Handles mPictureBox.MouseClick 
     If e.Button = MouseButtons.Left AndAlso shotFlag Then 
      Dim shot As New Point(e.X, e.Y) 
      shotList.Add(shot)    
      shotDist = ShotDistance(shot) 

      Me.lbDataPoints.Items.Insert(shotList.Count - 1, String.Format("SHOT - {0:N2} in.", shotDist)) 

      Me.txtShotCount.EditValue = shotList.Count 
      mPictureBox.Refresh() 
     End If 
    End Sub 

    Private Sub mPictureBox_Paint(sender As Object, e As PaintEventArgs) Handles mPictureBox.Paint 
     Dim calRad As Decimal = cboCaliber.EditValue/pLineDist()/2 

     For i As Integer = 0 To shotList.Count - 1 
      Dim shot As Point = shotList(i) 
      Dim dist As Double = ShotDistance(shot) 
      Dim labelLoc As New Point(shot.X + calRad, shot.Y + calRad) 
      Dim text As String = String.Format("Shot {0} - {1:N2} in.", i + 1, dist) 

      DrawShotLabel(e.Graphics, text, labelLoc) 
     Next i   
    End Sub 

    Private Sub DrawShotLabel(g As Graphics, label As String, location As Point) 
     Dim consolas As New Font("Consolas", 8) 
     Dim textSize As Size = g.MeasureString(label, consolas).ToSize() 
     g.FillRectangle(Brushes.White, New Rectangle(location, textSize)) 
     g.DrawString(label, consolas, Brushes.Black, location) 
    End Sub 

End Class 
+0

감사합니다. Joel. 나는이 접근법을 시도 할 것이다. –

+0

완벽한 작업. 나는 약간의 편집을했지만 중요한 것은하지 않았다. 감사! –