Casse per testo giustificato

venerdì 05 settembre 2008 - 20.56

ans66 Profilo | Junior Member

Vorrei avvisare che ho trovato una soluzione con le seguenti due funzioni da me create. Accetto comunque osservazione o miglioramenti delle ruotine:

Public Sub Testo_Giust2(ByVal pr As System.Drawing.Printing.PrintPageEventArgs, ByVal Testo As String, ByVal Alto As Single, ByVal Font As System.Drawing.Font)


Testo = Testo.Replace(Chr(10), "")
Testo = Testo.Replace(Chr(13), Space(1))
Testo = Testo.Replace(Space(2), Space(1))


Dim LargRiga As Single = (pr.MarginBounds.Right - pr.MarginBounds.Left)
Dim ritStr() As String = Split(Testo, Space(1))
Static RigaControllo As String = vbNullString
Static RigaDaScriv As String = vbNullString
Dim NrParola As Integer = 0, i As Integer = 0
Static LunghParola As Integer = 0

Alto = Alto + 90

For i = 0 To UBound(ritStr) - 1


If pr.Graphics.MeasureString(RigaControllo, Font).Width <= LargRiga Then
RigaControllo = RigaControllo & ritStr(i) & Space(1)
LunghParola = ritStr(i).Length + 1

Else

RigaDaScriv = Mid(RigaControllo, 1, RigaControllo.Length - LunghParola)
CentraTesto(pr, Alto, RigaDaScriv, Font, LargRiga)
' qui passi a funzione CentraTesto
Alto = Alto + 10
RigaControllo = Mid(RigaControllo, RigaDaScriv.Length + 1)
LunghParola = RigaControllo.Length
i = i - 1
End If

If i = UBound(ritStr) - 1 AndAlso pr.Graphics.MeasureString(RigaControllo, Font).Width <= LargRiga Then
RigaControllo = RigaControllo & ritStr(i + 1)
pr.Graphics.DrawString(RigaControllo, Font, Brushes.Black, pr.MarginBounds.Left, Alto)
End If


Next

RigaControllo = vbNullString
RigaDaScriv = vbNullString


End Sub

Public Sub CentraTesto(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal Top As Single, ByVal Rg As String, ByVal Fn As System.Drawing.Font, ByVal LargRiga As Single)

Dim LrgDascriv As Single = e.Graphics.MeasureString(Rg, Fn).Width
Dim Dif As Single = LargRiga - LrgDascriv
Dim Parole() As String = Split(Rg, Space(1))
Dim NrParole As Integer = UBound(Parole) - 1
Dim SpazioFraParole As Single = Dif / NrParole

Dim x As Single = e.MarginBounds.Left


For i As Integer = 0 To UBound(Parole) - 1
Dim LgParola As Single = e.Graphics.MeasureString(Parole(i) & Space(1), Fn).Width
e.Graphics.DrawString(Parole(i) & Space(1), Fn, Brushes.Black, x, Top)
x = x + LgParola + SpazioFraParole
Next

End Sub



End Module
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5