I draw lines that have a circle written inside the circle number 90. Now my problem is that the number 90 rotates with the rotation of the circle and becomes, for example, 09! How do I keep the writing direction constant? For example, always be down.
I want to be able to move the drawn line like this:
my codes are:
Imports System.Drawing.Drawing2D
Public Class Form1
Private Segments As List(Of Segment) = New List(Of Segment)()
Private NewSegment As Segment = Nothing
Dim P As Pen = New Pen(Color.Black, 1.5)
Dim CIRCLE, ELLIPSE As GraphicsPath
Dim radius = 15
Dim drawFontF As FontFamily = New FontFamily("times new roman")
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
Dim drawString = "90"
CIRCLE = New GraphicsPath()
CIRCLE.AddEllipse(-15, 0, radius * 2, radius * 2)
'****************************
Dim angle = Math.Atan2(20 - e.Location.Y, 5 - e.Location.X)
Dim x3 = 5 + Math.Cos(angle) * radius
Dim y3 = 20 + Math.Sin(angle) * radius
CIRCLE.AddString(drawString, drawFontF, FontStyle.Regular, 10, New Point(x3, y3), Nothing)
P.CustomEndCap = New CustomLineCap(Nothing, CIRCLE)
NewSegment = New Segment(P, e.Location, e.Location, "CIRCLE")
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If NewSegment Is Nothing Then Return
NewSegment.pt2 = e.Location
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
Dim PP As Pen = New Pen(Color.Black, 1.5)
PP.CustomEndCap = New CustomLineCap(Nothing, CIRCLE)
Dim H = "CIRCLE"
NewSegment.pen1 = PP
NewSegment.END_CAPS = H
Segments.Add(NewSegment)
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
For Each segment As Segment In Segments
segment.Draw(e.Graphics, Nothing, Nothing)
Next
If NewSegment IsNot Nothing Then
NewSegment.Draw(e.Graphics, Nothing, Nothing)
End If
End Sub
End Class
Class Segment
Public pen1 As Pen
Public pt1, pt2 As Point
Public END_CAPS As String
Public Sub New(pen As Pen, point1 As Point, point2 As Point, END_CAP As String)
pen1 = pen
pt1 = point1
pt2 = point2
END_CAPS = END_CAP
End Sub
Public Sub Draw(gr As Graphics, R As Rectangle, INDEX As Integer)
'*********************
gr.SmoothingMode = SmoothingMode.AntiAlias
gr.DrawLine(pen1, pt1, pt2)
End Sub
End Class