2008/05/13(Tue) 17:58:28 編集(投稿者)
'精度とか利便性とか拡張性とかはとりあえず無視して、
'Subプロシージャ作ってみました
Public Sub PrintText(ByVal DestPicture As PictureBox, ByVal PrintStr As String, ByVal TextFont As Font, _
ByVal PrintPos As Point, ByVal PrintSize As SizeF, ByVal FontColor As Blush)
Dim lcGrp As Graphic
Dim lcStrSize As SizeF
Dim lcRatioX As Single
Dim lcRatioY As Single
Dim lcStrFormat As StringFormat
Try
'PictureBoxのGraphics
lcGrp = DestPicture.CreateGraphics
lcGrp.ScaleTransform(1, 1) '念のため1:1に戻す
'空白も文字列サイズに含めるようフラグ設定
lcStrFormat = New StringFormat
lcStrFormat.FormatFlags = .FormatFlags Or StringFormatFlags.MeasureTrailingSpace
'文字列の幅高さを取得
lcStrSize = lcGrp.MeasureString(PrintStr, TextFont, DestPicture.Size, lcStrFormat)
'比率の計算
lcRatioX = PrintSize.Width / lcStrSize.Width
lcRatioY = PrintSize.Height / lcStrSize.Height
'描画
lcGrp.ScaleTransform(lcRatioX, lcRatioY)
lcGrp.DrawString(PrintStr, TextFont, FontColor, PrintPos.X, PrintPos.Y)
Catch ex As Exception
Throw ex
Finally
'lcGrp = Nothing
'lcStrFormat = Nothing
End Try
End Sub
'#Nothingしていいのかどうか迷った