K
Kirk Graves
I have an html table that I am filling with data from the database. when I
put the text in the table, I only display the number of characters that will
fit based on the size of the cell.
I know the width of the cell, I can get the length of the text, but the
cell.width is in pixels, while the text length is measured based on points
(font size).
anyone have any ideas how to get this to work? Here is the entire class I
am using.
Thank you in advance
Kirk
-------------------
Public Class TextCalc
Public Shared f As Drawing.Font
Public Shared g As Drawing.Graphics
Public Shared Ready As Boolean = False
Friend Shared Sub SetUpCalculator(ByVal FontFamily As String, ByVal
FontUnit As Web.UI.WebControls.Unit)
f = New Drawing.Font(FontFamily, Convert.ToSingle(FontUnit.Value),
CType(FontUnit.Type, Drawing.GraphicsUnit))
g = Drawing.Graphics.FromImage(New Drawing.Bitmap(100, 100))
Ready = True
End Sub
Friend Shared Function GetDisplayText(ByVal ItemText As String, ByVal
cellWidth As Single) As String
Dim l As Drawing.SizeF
Dim x As Int16
Dim s As String
l = g.MeasureString(ItemText, f)
If l.Width <= cellWidth Then ' this is the line that causes the
problem,
'l.Width is based on
points, cellWidth is based on pixels
Return ItemText
End If
For x = 1 To ItemText.Length
s = ItemText.Substring(0, x) & ".."
l = g.MeasureString(s, f)
If l.Width >= cellWidth Then
Exit For
End If
Next
Return s
End Function
End Class
put the text in the table, I only display the number of characters that will
fit based on the size of the cell.
I know the width of the cell, I can get the length of the text, but the
cell.width is in pixels, while the text length is measured based on points
(font size).
anyone have any ideas how to get this to work? Here is the entire class I
am using.
Thank you in advance
Kirk
-------------------
Public Class TextCalc
Public Shared f As Drawing.Font
Public Shared g As Drawing.Graphics
Public Shared Ready As Boolean = False
Friend Shared Sub SetUpCalculator(ByVal FontFamily As String, ByVal
FontUnit As Web.UI.WebControls.Unit)
f = New Drawing.Font(FontFamily, Convert.ToSingle(FontUnit.Value),
CType(FontUnit.Type, Drawing.GraphicsUnit))
g = Drawing.Graphics.FromImage(New Drawing.Bitmap(100, 100))
Ready = True
End Sub
Friend Shared Function GetDisplayText(ByVal ItemText As String, ByVal
cellWidth As Single) As String
Dim l As Drawing.SizeF
Dim x As Int16
Dim s As String
l = g.MeasureString(ItemText, f)
If l.Width <= cellWidth Then ' this is the line that causes the
problem,
'l.Width is based on
points, cellWidth is based on pixels
Return ItemText
End If
For x = 1 To ItemText.Length
s = ItemText.Substring(0, x) & ".."
l = g.MeasureString(s, f)
If l.Width >= cellWidth Then
Exit For
End If
Next
Return s
End Function
End Class