Curvare il testo in una DrawingArea: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| Riga 97: | Riga 97: | ||
With Paint | With Paint | ||
<FONT Color=gray>' ''Imposta la posizione del primo carattere del testo da disegnare ruotato:''</font> | |||
.Translate(Me.W / 2.5, Me.H / 1.5) | .Translate(Me.W / 2.5, Me.H / 1.5) | ||
.Rotate(Rad(160)) | .Rotate(Rad(160)) | ||
| Riga 104: | Riga 105: | ||
.DrawText(Chr(bb[0]), 0, 0, .Font.TextWidth(Chr(bb[0])), .Font.TextHeight(Chr(bb[0])), Align.Center) | .DrawText(Chr(bb[0]), 0, 0, .Font.TextWidth(Chr(bb[0])), .Font.TextHeight(Chr(bb[0])), Align.Center) | ||
<FONT Color=gray>' ''Imposta la posizione dei restanti caratteri del testo da disegnare ruotato:''</font> | |||
For b = 1 To bb.Max | For b = 1 To bb.Max | ||
.Font.Bold = False | .Font.Bold = False | ||
Versione delle 19:03, 3 giu 2021
Il caso è quello in cui si scrive un testo su una circonferenza ideale curvando ogni carattere in modo tale che il proprio asse verticale converga al centro di detta circonferenza. [Nota 1]
La rotazione è data dai valori presenti nei metodi "Paint.Traslate()" e "Paint.Rotate()" relativi alle misure dell'area di disegno e a quelle del testo.
Nell'esempio, che segue, si scriveranno alcuni caratteri lungo il semicerchio superiore della circonferenza:
Public Sub Form_Open()
Dim DrawingArea1 As DrawingArea
With Me
.Center
.W = 600
.H = 500
.Arrangement = Arrange.Fill
End With
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
.X = 0
.Y = 0
End With
End
Public Sub DrawingArea1_Draw()
With Paint
.Arc(300, 300, 50, Rad(0), 360, False)
.Stroke
.DrawRect(250, 250, 50, 50, Color.Red, 1.0)
.DrawRect(300, 250, 50, 50, Color.Red, 1.0)
.DrawRect(250, 300, 50, 50, Color.Red, 1.0)
.DrawRect(300, 300, 50, 50, Color.Red, 1.0)
.Translate(240, 304)
.Rotate(Rad(90))
.Font.Bold = True
.DrawText("A", 0, 0, 5, 5, Align.Left)
.Font.Bold = False
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("B", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("C", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("D", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("E", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("F", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("G", 0, 0, 5, 5, Align.Left)
.Translate(44, 14)
.Rotate(Rad(315))
.DrawText("H", 0, 0, 5, 5, Align.Left)
.End
End With
End
Altro esempio:
Public Sub Form_Open()
Dim DrawingArea1 As DrawingArea
With Me
.Center
.W = Screen.AvailableWidth
.H = Screen.AvailableHeight
.Arrangement = Arrange.Fill
End With
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
.X = 0
.Y = 0
End With
End
Public Sub DrawingArea1_Draw()
Dim b As Byte
Dim bb As Byte[]
bb = Byte[].FromString("Linguaggio Gambas")
With Paint
' Imposta la posizione del primo carattere del testo da disegnare ruotato:
.Translate(Me.W / 2.5, Me.H / 1.5)
.Rotate(Rad(160))
.Font.Size = 20
.Font.Bold = True
.Brush = .Color(Color.Red)
.DrawText(Chr(bb[0]), 0, 0, .Font.TextWidth(Chr(bb[0])), .Font.TextHeight(Chr(bb[0])), Align.Center)
' Imposta la posizione dei restanti caratteri del testo da disegnare ruotato:
For b = 1 To bb.Max
.Font.Bold = False
.Translate(60, 10)
.Rotate(Rad(340))
.Font.Size = 20
.Font.Bold = True
.Brush = .Color(Color.Red)
.DrawText(Chr(bb[b]), 0, 0, .Font.TextWidth(Chr(bb[b])), .Font.TextHeight(Chr(bb[b])), Align.Center)
Next
.End
End With
End
Note
[1] Vedere anche questa pagina: Curvare la linea di testo in un oggetto Image