[RESOLVED] Centre the text between the two radians irrespetive of text Legth and number.........
SUB: Centre the text between the two radians irrespetive of text Length and number of sections
Hello
I would like to Centre the text between the two radians irrespective of text length and number of sections
For eg if nos. of sections lets Say 8 therefore Radians are created at interval 45 degrees and its Centre should be 22.5.
In this Case Also nos. of sections are 16 therefore Radians are created at interval of 22.5 degrees and its Centre should be 11.25
NOTE 1: In this case the text are words of number of sections. Text could be anything
NOTE 2: Drawings, filling colours in Radians and Adding text are in different sub routines (Creating each layer.....) called them in Form Load Event
Any formula also could be worked out to get automatically the StartAngle value therefore Curved text in each radian is centred.
Some places I've marked in Red which could be considered as relevant factors .
Image Attached: if you see the image the text is not centered.
Code:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Color
Imports System.Drawing.SystemColors
Public Class TextInRadians
Private newImg As New Bitmap(700, 700)
Private gr As Graphics = Graphics.FromImage(newImg)
Private cPoint As Point = New Point(newImg.Width / 2, newImg.Width / 2)
Private NumberOfSections As Integer = 16
Private centXCrPicSq As Integer
Private centYCrPicSq As Integer
Private Sub TextInRadians_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim radiuss As Integer = newImg.Width / 2
EqualFacesWithText(gr, cPoint, radiuss, NumberOfSections)
Dim sldBrBlack As New SolidBrush(Black)
Dim centXCrPicSq As Integer
Dim centYCrPicSq As Integer
centXCrPicSq = (newImg.Width - PictureBox1.Width) \ 2
centYCrPicSq = (newImg.Height - PictureBox1.Height) \ 2
Dim centloc As New Point(centXCrPicSq, centXCrPicSq)
GetTextinSectionsLoop(gr, centloc, radiuss, sldBrBlack)
End Sub
Private Sub EqualFacesWithText(ByVal g As Graphics, ByVal centre As PointF, ByVal radius As Single, ByVal NumberOfSections As Integer)
Dim rad As Integer = CInt(radius)
g.TranslateTransform(centre.X, centre.Y)
Dim rim As New Rectangle(-radius, -radius, radius * 2, radius * 2)
Dim bsh() As Brush = {Brushes.Orange, Brushes.PaleGoldenrod}
Dim sweepAngle As Single = 360 / NumberOfSections
Dim br As Integer = 0
g.RotateTransform(-sweepAngle - 11.25)
For ang As Single = -90 To 360 - 90 - sweepAngle Step sweepAngle
g.FillPie(bsh(br Mod 2), rim, ang, sweepAngle)
g.DrawPie(New Pen(Color.Orange, 2), rim, ang, sweepAngle)
br += 1
Next
PictureBox1.Image = newImg
End Sub
Private Sub GetTextinSectionsLoop(ByVal g As Graphics, ByVal centre As PointF, ByVal radius As Single, ByVal sldBr As SolidBrush)
Dim numberOfSections As Integer = 16
Dim CentrepointImg As Point = New Point(centre.X, centre.Y)
Dim nfont = New Font("Arial", 15, FontStyle.Bold)
Dim textArray As String() = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN"}
Dim sweepAngle As Single = 360 / numberOfSections
Dim startAngle = 107
For i As Integer = 0 To UBound(textArray)
DrawCurvedTextinSections(gr, textArray(i), startAngle, CentrepointImg, radius - 55, nfont, sldBr)
startAngle = startAngle + sweepAngle
Next i
End Sub
Private Sub DrawCurvedTextinSections(ByVal graphics As Graphics, ByVal text As String, ByVal startAngle As Single, ByVal centre As Point, ByVal distanceFromCentreToBaseOfText As Single, ByVal font As Font, ByVal sBrush As SolidBrush)
Dim circleCircumference = CSng((2 * Math.PI * distanceFromCentreToBaseOfText))
Dim characterWidths = GetCharacterWidths(graphics, text, font).ToArray()
Dim characterHeight = graphics.MeasureString(text, font).Height
Dim textLength = characterWidths.Sum()
Dim radiansToTxtCent As Single = ((startAngle - characterWidths.Average) + distanceFromCentreToBaseOfText) * Math.PI / 180
Dim fractionOfCircumference As Single = textLength / circleCircumference '
Dim currentCharacterRadians As Single = radiansToTxtCent + CSng((Math.PI * fractionOfCircumference))
For characterIndex As Integer = 0 To text.Length - 1
Dim charac As Char = text(characterIndex)
Dim x As Single = CSng((distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians)))
Dim y As Single = CSng((distanceFromCentreToBaseOfText * -Math.Cos(currentCharacterRadians)))
Using characterPath As GraphicsPath = New GraphicsPath()
characterPath.AddString(charac.ToString(), font.FontFamily, CInt(font.Style), font.Size, Point.Empty, StringFormat.GenericTypographic)
Dim pathBounds = characterPath.GetBounds()
Dim transform = New Matrix()
transform.Translate(centre.X + x, centre.Y + y)
Dim rotationAngleDegrees = (currentCharacterRadians * 180.0F / CSng(Math.PI)) '- 180.0F
transform.Rotate(rotationAngleDegrees)
transform.Translate(-pathBounds.Width / 2.0F, -characterHeight) '2
characterPath.Transform(transform)
graphics.FillPath(sBrush, characterPath)
End Using
If characterIndex <> text.Length - 1 Then
Dim distanceToNextChar = (characterWidths(characterIndex) + characterWidths(characterIndex + 1)) / 3.0F '2
Dim charFractionOfCircumference As Single = distanceToNextChar / circleCircumference
currentCharacterRadians += charFractionOfCircumference * CSng(2.0F * Math.PI)
End If
Next
End Sub
Private Function GetCharacterWidths(ByVal graphics As Graphics, ByVal text As String, ByVal font As Font) As IEnumerable(Of Single)
Dim spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width
Return text.[Select](Function(c) If(c = " "c, spaceLength, graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width))
End Function
End Class
Re: Centre the text between the two radians irrespetive of text Legth and number.....
FordPrefect
Also, I read as far as 'GetTextinSections(gr, centloc, radiuss, sldBrBlack)' and realized that there is no such Sub routine in the code. I could guess that adding 'Loop' to the call might achieve something - however, I read no further.
Thanks for pointing it out. Inconvenience regretted
It should have been GetTextinSectionsLoop(gr, centloc, radiuss, sldBrBlack) which is now marked in blue in the code in OP . Sending the image of original code posted in OP #1
Re: Centre the text between the two radians irrespetive of text Legth and number.....
Obviously, your font is too large, or your clock is too small.
By the look of FordPrefect’s code, gap is the distance between the text and the outer edge of your clock.
Re: Centre the text between the two radians irrespetive of text Legth and number.....
.Paul. Sir,
Obviously, your font is too large, or your clock is too small.
By the look of FordPrefect’s code, gap is the distance between the text and the outer edge of your clock.
Exactly. I also got bit surprised because
I've used the same size of Font as What FordPrefect has used in other words just copied the code and pasted into new file.
If FordPrefect mentions the Picturebox Size ie. PB (name of PicturBox) and if not mistaken he has used ClientSize while coding. If some concrete things are shown then we can compare Apple to Apple
Thank you so much for the clarification of
gap is the distance between the text and the outer edge of your clock
Re: Centre the text between the two radians irrespetive of text Legth and number.....
FordPrefect
Hi
These difference will be caused by resolution/dpi/settings of your/my environment. For example, due to deteriorating eyesight, I have had to use a larger scale setting (Display settings), and other changes too. I would say you can likely bring things closer by adjusting the font size as per .Paul. above. The fontsize variable at the top of the code is 60 in mine - try changing that (Dim sizeFont As Integer = 60). The Gap is a variable use all the way through from your original code. Although lots of changes, I started from that code and worked as near as I could to keep as much as possible. The Gap is the distance from both left edge and top to fit the drawing into. Why you would ask me to explain code you posted to you explains a lot. Copy/paste is always fraught with issues - as you have found with this latest question.
As for Close/Minimize etc - well I have them too, the image I posted was of the image, not the Form
Thankx, Let me check, Test by changing the Font size to Small < 60 and revert
Re: Centre the text between the two radians irrespetive of text Legth and number.....
Yes I changed to Font size 40 and it came correctly Image1 for Reference
I really can understand the frustration you guys going through for helping me out and I feel embarrassed to bother you for teething issues.
Just a simple math and logic cannot set in my brains.
Unfortunately my Math is BAD and find it difficult for Clock/Circle to Divide into 16 Sections and get Appropriate Text at 11.5 degrees.
What should be the logic in order to divide all the Sixteen words in 16 sections
For Following syntaxes
1. For i As Single = 0 To 59
2. Dim innerRadius As Single = If(i Mod 5 = 0, radius - (radius * 0.1F), radius - (radius * 0.06F))
3. If (i Mod 5 = 0) Then
4. StudentsDrawRotatedText(gr, roman((ch) Mod 12), CSng(((i \ 5 + 3) Mod 12) * 30)
Although I tried with the following the result did not come correctly.
Code:
Imports System.Drawing.Drawing2D
Public Class Form1
Dim roman As String() = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN"}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1400
Height = 1400
gap = 80
radius = Math.Min(PB.Width, PB.Height) / 2 - gap
newImgClock = New Bitmap(radius * 2 + gap * 2, radius * 2 + gap * 2)
gr = Graphics.FromImage(newImgClock)
cPoint = New Point(radius + gap, radius + gap)
'SegMents(gr, cPoint)
SegMents16(gr, cPoint)
'NewDrawClockFace(gr, cPoint, radius, gap)
NewDraw16Faces((gr, cPoint, radius, gap))
PB.SizeMode = PictureBoxSizeMode.Zoom
End Sub
Public Sub NewDraw16Faces(g As Graphics, centre As PointF, radius As Single, gap As Integer)
For i As Single = 0 To 359 '59
Dim angle As Double = Math.PI * 2 * i / 16 '60
Dim a As Double = Math.PI * 2 / roman.Length / 2
' Outer point of the tick mark
Dim outerX As Single = centre.X + CSng(Math.Cos(angle) * radius)
Dim outerY As Single = centre.Y + CSng(Math.Sin(angle) * radius)
' Inner point of the tick mark
'Dim innerRadius As Single = If(i Mod 5 = 0, radius - (radius * 0.1F), radius - (radius * 0.06F))
Dim innerRadius As Single = If(i Mod 22.5 = 0, radius - (radius * 0.1F), radius - (radius * 0.06F))
Dim innerX As Single = centre.X + CSng(Math.Cos(angle) * innerRadius)
Dim innerY As Single = centre.Y + CSng(Math.Sin(angle) * innerRadius)
Dim innerXfont As Single = centre.X + CSng(Math.Cos(angle) * (radius * 0.9F - sizeFont))
Dim innerYfont As Single = centre.Y + CSng(Math.Sin(angle) * (radius * 0.9F - sizeFont))
If (i Mod 22.5 = 0) Then '(i Mod 5 = 0)
'g.DrawLine(New Pen(Color.Blue, 10), New PointF(outerX, outerY), New PointF(innerX, innerY))
'StudentsDrawRotatedText(gr, roman((newCh) Mod 12), CSng(((i \ 5 + 3) Mod 12) * 30), innerXfont, innerYfont)
StudentsDrawRotatedText(gr, roman((newCh) Mod 16), CSng(((i \ 22.5) Mod 16) * 11.5), innerXfont, innerYfont)
newCh += 1
Else
g.DrawLine(New Pen(Color.Black, 5), New PointF(outerX, outerY), New PointF(innerX, innerY))
End If
Next
' extras
Using p As New Pen(Color.Black, 2)
'g.DrawEllipse(p, New Rectangle(gap, gap, radius * 2, radius * 2))
'g.FillEllipse(Brushes.Blue, New Rectangle(gap + radius - radius \ 32, gap + radius - radius \ 32, radius \ 16, radius \ 16))
'g.DrawEllipse(p, New Rectangle(gap + radius - radius \ 8, gap + radius - radius \ 8, radius \ 4, radius \ 4))
'g.DrawEllipse(p, New Rectangle(gap + radius * 0.06, gap + radius * 0.06, (radius - radius * 0.06) * 2, (radius - radius * 0.06) * 2))
End Using
'PB.Image
PB.Image = newImgClock
End Sub
Sub SegMents16(g As Graphics, ctr As PointF)
Dim segnum As Integer = 16
Dim seglines As Boolean = True
Dim rad As Integer = CInt((Math.Min(ClientSize.Width, ClientSize.Height) \ 2) * 0.9)
g.TranslateTransform(ctr.X, ctr.Y)
Dim rim As New Rectangle(-radius, -radius, radius * 2, radius * 2)
Dim bsh() As Brush = {New SolidBrush(Color.FromArgb(160, 238, 232, 170)), New SolidBrush(Color.FromArgb(160, 255, 250, 205))}
'Dim bsh() As Brush = {New SolidBrush(Color.PaleGoldenrod), New SolidBrush(Color.LemonChiffon)}
Dim sweepAngle As Single = CSng(360 / segnum)
'360/16 = 22.5 *1/2 =11.5
Dim br As Integer = 0
For ang As Single = -90 + 11.5 To 360 - 90 - sweepAngle + 11.5 Step sweepAngle
g.FillPie(bsh(br), rim, ang, sweepAngle)
If seglines Then gr.DrawPie(New Pen(Color.Red, 4), rim, ang, sweepAngle)
br += 1
If br > 1 Then br = 0
Next
g.ResetTransform()
End Sub
Re: Centre the text between the two radians irrespetive of text Legth and number.....
FordPrefect
Hi
Major re-write required for that.
I've re-written the code but not satisfied. The text still gets rotated rather than appropriately.
Also to get "One" at position of Twelve
Image attached.
Code:
Imports System.Drawing.Drawing2D
Public Class Form1
Dim radius As Integer = 0
Dim newImg As Bitmap
Dim gr As Graphics = Nothing
Dim cPoint As Point
Dim gap As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1400
Height = 1400
gap = 80
radius = Math.Min(PB.Width, PB.Height) / 2 - gap
newImg = New Bitmap(radius * 2 + gap * 2, radius * 2 + gap * 2)
gr = Graphics.FromImage(newImg)
cPoint = New Point(radius + gap, radius + gap)
SegMents16(gr, cPoint)
NewcircleFaces16(gr, cPoint)
PB.Image = newImg
PB.SizeMode = PictureBoxSizeMode.Zoom
End Sub
Private Sub SegMents16(g As Graphics, ctr As PointF)
Dim segnum As Integer = 16
Dim seglines As Boolean = True
Dim rad As Integer = CInt((Math.Min(ClientSize.Width, ClientSize.Height) \ 2) * 0.9)
g.TranslateTransform(ctr.X, ctr.Y)
Dim rim As New Rectangle(-radius, -radius, radius * 2, radius * 2)
Dim bsh() As Brush = {New SolidBrush(Color.FromArgb(160, 238, 232, 170)), New SolidBrush(Color.FromArgb(160, 255, 250, 205))}
'Dim bsh() As Brush = {New SolidBrush(Color.PaleGoldenrod), New SolidBrush(Color.LemonChiffon)}
Dim sweepAngle As Single = CSng(360 / segnum)
'360/16 = 22.5 *1/2 =11.5
Dim br As Integer = 0
For ang As Single = -90 + 11.5 To 360 - 90 - sweepAngle + 11.5 Step sweepAngle
g.FillPie(bsh(br), rim, ang, sweepAngle)
If seglines Then gr.DrawPie(New Pen(Color.Red, 4), rim, ang, sweepAngle)
br += 1
If br > 1 Then br = 0
Next
g.ResetTransform()
End Sub
Private Sub NewcircleFaces16(g As Graphics, ctr As PointF)
g.SmoothingMode = SmoothingMode.AntiAlias ' Smooth rendering
'Dim centre As PointF = New PointF(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
'Dim centre As PointF = New PointF(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
Dim radius As Integer = 100 '100 ' Radius of the circle
Dim NosOfsections As Integer = 16 '8 ' Number of sections (Adjust as needed)
Dim font As New Font("Arial", 12, FontStyle.Bold)
Dim brush As Brush = Brushes.Black
'Dim sldBrBlack As New SolidBrush(Black)
' Calculate section angle
Dim sectionAngle As Single = 360.0F / NosOfsections
Dim textArray As String() = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN"}
'cPoint = New Point(radius + gap, radius + gap)
For i As Integer = 0 To NosOfsections - 1
' Angle for each section (convert to radians)
Dim angle As Single = i * sectionAngle
Dim radian As Double = angle * Math.PI / 180
' Calculate text position on the circle
'Dim textX As Single = center.X + radius * Math.Cos(radian) - 20
'Dim textY As Single = center.Y + radius * Math.Sin(radian) - 10
Dim textX As Single = ctr.X + radius * Math.Cos(radian) - 20
Dim textY As Single = ctr.Y + radius * Math.Sin(radian) - 10
' Rotate and draw text
g.TranslateTransform(textX, textY)
g.RotateTransform(angle)
DrawCurvedTextinSections(gr, textArray(i), i, New Point(radius, radius), radius - 55, font, brush)
g.ResetTransform()
Next
End Sub
Private Sub DrawCurvedTextinSections(ByVal graphics As Graphics, ByVal text As String, ByVal startAngle As Single, ByVal centre As Point, ByVal distanceFromCentreToBaseOfText As Single, ByVal font As Font, ByVal sBrush As SolidBrush)
Dim circleCircumference = CSng((2 * Math.PI * distanceFromCentreToBaseOfText))
Dim characterWidths = GetCharacterWidths(graphics, text, font).ToArray()
Dim characterHeight = graphics.MeasureString(text, font).Height
Dim textLength = characterWidths.Sum()
Dim radiansToTxtCent As Single = ((startAngle - characterWidths.Average) + distanceFromCentreToBaseOfText) * Math.PI / 180
Dim fractionOfCircumference As Single = textLength / circleCircumference '
Dim currentCharacterRadians As Single = radiansToTxtCent + CSng((Math.PI * fractionOfCircumference))
For characterIndex As Integer = 0 To text.Length - 1
Dim charac As Char = text(characterIndex)
Dim x As Single = CSng((distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians)))
Dim y As Single = CSng((distanceFromCentreToBaseOfText * -Math.Cos(currentCharacterRadians)))
Using characterPath As GraphicsPath = New GraphicsPath()
characterPath.AddString(charac.ToString(), font.FontFamily, CInt(font.Style), font.Size, Point.Empty, StringFormat.GenericTypographic)
Dim pathBounds = characterPath.GetBounds()
Dim transform = New Matrix()
transform.Translate(centre.X + x, centre.Y + y)
Dim rotationAngleDegrees = (currentCharacterRadians * 180.0F / CSng(Math.PI)) '- 180.0F
transform.Rotate(rotationAngleDegrees)
transform.Translate(-pathBounds.Width / 2.0F, -characterHeight) '2
characterPath.Transform(transform)
graphics.FillPath(sBrush, characterPath)
End Using
If characterIndex <> text.Length - 1 Then
Dim distanceToNextChar = (characterWidths(characterIndex) + characterWidths(characterIndex + 1)) / 3.0F '2
Dim charFractionOfCircumference As Single = distanceToNextChar / circleCircumference
currentCharacterRadians += charFractionOfCircumference * CSng(2.0F * Math.PI)
End If
Next
End Sub
Private Function GetCharacterWidths(ByVal graphics As Graphics, ByVal text As String, ByVal font As Font) As IEnumerable(Of Single)
Dim spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width
Return text.[Select](Function(c) If(c = " "c, spaceLength, graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width))
End Function
Re: Centre the text between the two radians irrespetive of text Legth and number.....
You're still doing the same confusing thing where you declare "gr" as a form level variable, but then you're passing it as a parameter all over the place to various subs, sometimes naming the parameter "gr", other times "graphics". That's not causing the issue, but it makes your code confusing.
In my opinion, your most recent posted code indicates that you're not doing enough pen and paper trig calculations. You need to nail down the math and logic clearly before you write a single line of code.
Re: Centre the text between the two radians irrespetive of text Legth and number.....
You're still doing the same confusing thing where you declare "gr" as a form level variable, but then you're passing it as a parameter all over the place to various subs, sometimes naming the parameter "gr", other times "graphics". That's not causing the issue, but it makes your code confusing.
I've realized the mistake just now.
Thanks OptionBase1 for pointing it out. It Still executed and therefore did not realize at all. No wonder no sooner replies were seen.
Very frustrating for you all.
FYI I've changed in red and bold in the code of #12 ,#10 #1.
In my opinion, your most recent posted code indicates that you're not doing enough pen and paper trig calculations. You need to nail down the math and logic
clearly before you write a single line of code.
It's not that I am not doing not doing enough pen and paper trig calculations. To do some calculations some logic needs to be set. This is where I am not able to set.
Require ones opinion Which is better logic to be used for this case? For Centered Rotate Text seen in 16 different parts.
The Logic which FordPrefect provided was indeed fabulous in # 4. Not denying it.
But using the same for 16 sections in this case where I did not succeed I came with another Logic in #12 with rotation in mind just below the circumference of circle.
Inconvenience regretted for passing gr as parameter in the subs
Re: Centre the text between the two radians irrespetive of text Legth and number.....
An attempt but not successful
Marked in Red to get proper calculations
to see the differentiation
For i as Single = 0 To 359 are written Twice in NewDrawCircleFace(gr, cPoint, radius, gap)
and changed the angle formula marked in blue
Will be really grateful to whoever helps me.
Code:
Imports System.Drawing.Drawing2D
Public Class Form1
'Dim roman() As String = {"XII", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI"}
'Dim roman() As String = {"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "One", "Two"}
Dim NumbersSixteen() As String = {"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "One", "Two"}
Dim radius As Integer = 0
Dim newImgClock As Bitmap
Dim gr As Graphics = Nothing
Dim cPoint As Point
Dim gap As Integer
Dim sizeFont As Integer = 20
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1400
Height = 1400
gap = 80
radius = Math.Min(PB.Width, PB.Height) / 2 - gap
newImgClock = New Bitmap(radius * 2 + gap * 2, radius * 2 + gap * 2)
gr = Graphics.FromImage(newImgClock)
cPoint = New Point(radius + gap, radius + gap)
SegMents(gr, cPoint)
NewDrawCircleFace(gr, cPoint, radius, gap)
PB.SizeMode = PictureBoxSizeMode.Zoom
End Sub
Public Sub NewDrawCircleFace(g As Graphics, centre As PointF, radius As Single, gap As Integer)
Dim cBrush As SolidBrush = New SolidBrush(Color.DarkBlue)
Dim ch As Integer = 0
For i As Single = 0 To 359 '59
'Dim angle As Double = Math.PI * 2 * i / 360
Dim angle As Double = Math.PI * i / 30
' Outer point of the tick mark
Dim outerX As Single = centre.X + CSng(Math.Cos(angle) * radius)
Dim outerY As Single = centre.Y + CSng(Math.Sin(angle) * radius)
'' Inner point of the tick mark
Dim innerRadius As Single = If(i Mod 5 = 0, radius - (radius * 0.1F), radius - (radius * 0.06F))
Dim innerX As Single = centre.X + CSng(Math.Cos(angle) * innerRadius)
Dim innerY As Single = centre.Y + CSng(Math.Sin(angle) * innerRadius)
Dim innerXfont As Single = centre.X + CSng(Math.Cos(angle) * (radius * 0.9F - sizeFont))
Dim innerYfont As Single = centre.Y + CSng(Math.Sin(angle) * (radius * 0.9F - sizeFont))
If (i Mod 5 = 0) Then
g.DrawLine(New Pen(Color.Blue, 2), New PointF(outerX, outerY), New PointF(innerX, innerY))
'StudentsDrawRotatedText(gr, roman((ch) Mod 12), CSng(((i \ 5 + 3) Mod 12) * 30), innerXfont, innerYfont)
ch += 1
''Else
''g.DrawLine(New Pen(Color.Black, 1), New PointF(outerX, outerY), New PointF(innerX, innerY))
End If
Next
For i As Single = 0 To 359
Dim angle As Double = Math.PI * 2 * i / 22.5
' Outer point of the tick mark
Dim outerX As Single = centre.X + CSng(Math.Cos(angle) * radius)
Dim outerY As Single = centre.Y + CSng(Math.Sin(angle) * radius)
' Inner point of the tick mark
Dim innerRadius As Single = If(i Mod 11.25 = 0, radius - (radius * 0.1F), radius - (radius * 0.06F))
Dim innerX As Single = centre.X + CSng(Math.Cos(angle) * innerRadius)
Dim innerY As Single = centre.Y + CSng(Math.Sin(angle) * innerRadius)
Dim innerXfont As Single = centre.X + CSng(Math.Cos(angle) * (radius * 0.9F - sizeFont))
Dim innerYfont As Single = centre.Y + CSng(Math.Sin(angle) * (radius * 0.9F - sizeFont))
If (i Mod 16 = 0) Then
g.DrawLine(New Pen(Color.Red, 5), New PointF(outerX, outerY), New PointF(innerX, innerY))
StudentsDrawRotatedText(gr, NumbersSixteen((ch) Mod 16), CSng(((i \ 22.5 + 16) Mod 16) * 22.5), innerXfont, innerYfont)
ch += 1
End If
Next
' extras
Using p As New Pen(Color.Black, 2)
g.DrawEllipse(p, New Rectangle(gap, gap, radius * 2, radius * 2))
g.FillEllipse(Brushes.Blue, New Rectangle(gap + radius - radius \ 32, gap + radius - radius \ 32, radius \ 16, radius \ 16))
'g.DrawEllipse(p, New Rectangle(gap + radius - radius \ 8, gap + radius - radius \ 8, radius \ 4, radius \ 4))
'g.DrawEllipse(p, New Rectangle(gap + radius * 0.06, gap + radius * 0.06, (radius - radius * 0.06) * 2, (radius - radius * 0.06) * 2))
End Using
PB.Image = newImgClock
End Sub
Sub SegMents(gr As Graphics, ctr As PointF)
Dim segnum As Integer = 16
Dim seglines As Boolean = True
Dim rad As Integer = CInt((Math.Min(ClientSize.Width, ClientSize.Height) \ 2) * 0.9)
gr.TranslateTransform(ctr.X, ctr.Y)
Dim rim As New Rectangle(-radius, -radius, radius * 2, radius * 2)
Dim bsh() As Brush = {New SolidBrush(Color.FromArgb(160, 238, 232, 170)), New SolidBrush(Color.FromArgb(160, 255, 250, 205))}
'Dim bsh() As Brush = {New SolidBrush(Color.PaleGoldenrod), New SolidBrush(Color.LemonChiffon)}
Dim sweepAngle As Single = CSng(360 / segnum)
Dim br As Integer = 0
For ang As Single = -90 + 15 To 360 - 90 - sweepAngle + 15 Step sweepAngle
gr.FillPie(bsh(br), rim, ang, sweepAngle)
If seglines Then gr.DrawPie(New Pen(Color.Red, 4), rim, ang, sweepAngle)
br += 1
If br > 1 Then br = 0
Next
gr.ResetTransform()
End Sub
Re: Centre the text between the two radians irrespetive of text Legth and number.....
FordPrefect
Indeed Brilliant, What a perfection ? Excellent Dear.
What you have coded with logic is really unbelievable.
Lastly I was thinking to change the Text of color in each section
I tried modifying DrawRotatedText(gr.......) but it accepted only last colour of the loop only
Code:
Private Sub DrawRotatedText(gr As Graphics, txt As String, angle As Single, cx As Integer, cy As Integer)
Dim string_format As New StringFormat With {
.Alignment = StringAlignment.Center,
.LineAlignment = StringAlignment.Center}
Dim graphics_path As New GraphicsPath(FillMode.Winding)
graphics_path.AddString(txt, fntfam, fntstyle, fntsize, New Point(cx, cy), string_format)
Dim rotation_matrix As New Matrix
rotation_matrix.RotateAt(angle, New PointF(cx, cy))
graphics_path.Transform(rotation_matrix)
'gr.FillPath(Brushes.Blue, graphics_path)
Dim br As Integer = 0
Dim sldBrwhite As New SolidBrush(White)
Dim sldBrDB As New SolidBrush(DarkBlue)
Dim sldBrGreen As New SolidBrush(Green)
Dim sldBrRed As New SolidBrush(Red)
Dim sldBrBlack As New SolidBrush(Black)
Dim bsh() As Brush = {sldBrwhite, sldBrwhite, sldBrDB, sldBrwhite,
sldBrwhite, sldBrwhite, sldBrwhite, sldBrwhite, sldBrwhite, sldBrDB, sldBrDB, sldBrDB, sldBrDB, sldBrDB, sldBrDB, sldBrBlack}
For i As Integer = 1 To bsh.Length
gr.FillPath(bsh(br) , graphics_path)
br += 1
Next i
End Sub
Re: Centre the text between the two radians irrespetive of text Legth and number.....
FordPrefect
Indeed that was very quick response
You MUST use the three lines I show in my code, the first 3 lines. If you do not use those then it adds errors that you then expect someone here to fix for you and is a very lazy thing to do
FYI I've managed it without First 3 lines of Option Strict.... and without using the Paint Event
I am indeed grateful to your efforts in helping me out. God Bless you Dear.
Thank you so much
See the Image Attached. Indeed One can create so many things
Re: Centre the text between the two radians irrespetive of text Legth and number.....
Originally Posted by nkvb
FYI I've managed it without First 3 lines of Option Strict.... and without using the Paint Event
It’s not a wise decision ignoring FordPrefect’s good advice.
It’s also better to learn the code you’re already using, instead of blindly moving on to a new implementation…
Re: [RESOLVED] Centre the text between the two radians irrespetive of text Legth and
.Paul. Sir,
It’s not a wise decision ignoring FordPrefect’s good advice.
It’s also better to learn the code you’re already using, instead of blindly moving on to a new implementation…
In thread 909935 majority of members were for FordPrefect's good advice. How can anyone avoid it ?
Kindly excuse me for this case.
Definately Sir, will always learn the code before implementing something new.