OS:WinXp
環境:VS2005(VB)
印字方法:PrintDocument
表題の件のとおり文字を中央揃えで印字したいです。
具体的に知りたいのは印字する文字の幅を取得方法です。
どうすればよいのでしょうか
んーと、DrawString で描画しているなら、StringFormat を指定するやつを使えば簡単に中央ぞろえできますが。
http://msdn2.microsoft.com/ja-jp/library/332kzs7c(VS.80).aspx
に以下のコードがありましたので使えそうです。
ありがとうございました。
Dim text1 As String = "Use StringFormat and Rectangle objects to" & _
" center text in a rectangle."
Dim font1 As New Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point)
Try
Dim rect1 As New Rectangle(10, 10, 130, 140)
' Create a StringFormat object with the each line of text, and the block
' of text centered on the page.
Dim stringFormat As New StringFormat()
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
' Draw the text and the surrounding rectangle.
e.Graphics.DrawString(text1, font1, Brushes.Blue, rect1, stringFormat)
e.Graphics.DrawRectangle(Pens.Black, rect1)
Finally
font1.Dispose()
End Try
ツイート | ![]() |