2017-03-11 2 views
2

Je développe un logiciel cible et j'ai besoin de garder une trace des photos sur la boîte à image en utilisant un cordon et un nombre par le cercle. Mon problème est que chaque cercle que je dessine, tous les nombres sur le cercle précédent se mettent à jour (c.-à-d. 4 cercles ont tous "4", dessinent un autre et ils mettent tous à jour à "5", etc.).Incrémenter le texte sur les cercles de dessin (Liste de)

Je joins une image et mon code: enter image description here

Voici le code:

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 

Ce code n'incrémente pas, mais ne montre et persistent les distances

+0

Le Bullet devrait être une classe. Ensuite, stockez chaque balle dans une 'Liste (Of T)'. Au fur et à mesure qu'ils bougent, vous mettez à jour leur emplacement, puis vous peignez chaque balle à son emplacement correct. Quand ils quittent la zone de travail, supprimez-les de la liste. – OneFineDay

+0

Chaque balle est dans une classe, dites-vous déplacer la chaîne de texte à sa propre classe? Merci –

+0

J'ai ajouté une classe BulletNo pour gérer le texte et maintenant j'appelle: Pour chaque t En tant qu'entier En _shotNo Dim _shot comme nouveau BulletNo (e.Graphics, _shotX, _shotY, n, "Consolas") Suivant. Cela affiche le nombre, mais supprime les autres chaînes de texte de prise de vue. –

Répondre

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

Merci Joel. Je vais essayer cette approche. –

+0

A travaillé parfait. J'ai fait quelques modifications, mais rien de majeur. Merci! –