We help IT Professionals succeed at work.

Increment Text on Drawing Circles (List of)

vwalla asked
Last Modified: 2017-03-16
I am developing a target software and I need to keep track of shots on the picturebox using drawstring and a number by the circle. My issue is that every circle I draw, all the numbers on the previous circle update to the same (i.e. 4 circles all have "4", draw another and they all update to "5", etc.).

Every time I click (add a shot) I want to increment the number (1,2,3,etc.)

I have attached an image and my code:

Here is my code:

Bullet Class

Public Class Bullet

Sub New(ByVal g As Graphics, ByRef center As Point, ByVal radius As Integer, ByVal ShotNo As Integer,
        ByRef x As Integer, ByVal y As Integer, ByVal txt As String, _font As String)

    ' Select a pen object and make it red
    Dim inPn As New Pen(My.Settings.Shot_Color_InnerCircle)
    Dim osPn As New Pen(My.Settings.Shot_Color_OuterCircle)
    Dim pnCtr As New Pen(My.Settings.Shot_Color_CenterMark)
    Dim pnDist As New Pen(My.Settings.Shot_Color_RadiusLine)

    Dim lineDash As Single() = {3, 3}
    Dim osDash As Single() = {1, 1}
    pnDist.DashPattern = lineDash
    osPn.DashPattern = osDash
    ' Create a bounding rectangle and make its center the center of our point
    ' Then make its width 2 * the radius
    ' Then draw our ellipse
    Dim hole As New Rectangle(center.X - radius, center.Y - radius, radius * 2, radius * 2)
    Dim perHol As New Rectangle(center.X - radius - 2, center.Y - radius - 2, radius * 2 + 4, radius * 2 + 4)
    _shotX = center.X
    _shotY = center.Y
    g.DrawEllipse(inPn, hole)
    g.DrawEllipse(osPn, perHol)
    g.DrawLine(pnCtr, New Point(_shotX, _shotY + 1), New Point(_shotX, _shotY - 1)) 'draw vert line
    g.DrawLine(pnCtr, New Point(_shotX + 1, _shotY), New Point(_shotX - 1, _shotY)) 'draw horiz line
    g.DrawLine(pnDist, _poaX, _poaY, _shotX, _shotY)

    Dim newFont = New Font(_font, 8)
    Dim textSize As Size = g.MeasureString(txt, newFont).ToSize
    g.FillRectangle(Brushes.White, New Rectangle(New Point(x, y), textSize))
    g.DrawString(txt, newFont, Brushes.Black, x, y)

End Sub
End Class

Open in new window

Shot Count Class

Public Class ShotCount
    Sub New(ByVal g As Graphics, ByRef center As Point, ByVal radius As Integer, _font As String, txt As String)
        Dim newFont = New Font(_font, 8)
        Dim wBrush As New SolidBrush(Color.White)
        Dim bBrush As New SolidBrush(Color.Black)
        Dim textSize As Size = g.MeasureString(txt, newFont).ToSize
        g.FillRectangle(wBrush, New Rectangle(New Point(center.X, center.Y), textSize))
        g.DrawString(txt, newFont, bBrush, center.X, center.Y)

    End Sub
End Class

Open in new window

mPictureBox Paint:
        For Each b As Point In shotList
            Dim _Bullet As New Bullet(e.Graphics, b, cboCaliber.EditValue / pLineDist() / 2, n)

        'SHOT number
        For Each s As Point In ShotCount
            Dim _shot As New ShotCount(e.Graphics, s, cboCaliber.EditValue / pLineDist() / 2, "Consolas", _s)

Open in new window

Watch Question

Most Valuable Expert 2011
Top Expert 2015
Unlock this solution and get a sample of our free trial.
(No credit card required)


That was the issue. Thanks.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.