When programming printing code
<Answers>
Yang Ning:
You can
Reason is: when printing string size is resolution
And if you using MeasureString function or use defaultgraphic StringFormat object
the result will be smaller than the true one
Below is sample code:
Public Shared Function GetTextSize(ByVal g As Graphics
ByVal text As String
ByVal textFont As Font) As SizeF
If text
Dim s As StringFormat = StringFormat
s
Dim textRect As RectangleF
Dim characterRanges As CharacterRange() = {New CharacterRange(
s
textRect = g
Return New SizeF(textRect
End Function
BTW:
We found a bug when we use code like above
Public Shared Function GetTextSize(ByVal g As Graphics
ByVal text As String
ByVal textFont As Font) As SizeF
If text
Dim s As StringFormat = StringFormat
Dim oldFlags As StringFormatFlags
oldFlags = s
s
Try
Dim textRect As RectangleF
Dim characterRanges As CharacterRange() = {New CharacterRange(
s
textRect = g
Return New SizeF(textRect
Finally
StringFormat
End Try
End Function
From:http://tw.wingwit.com/Article/program/net/201311/13206.html