印刷の一行目、右詰めと左詰めに印刷するには?

解決


白虎  2005-06-07 07:45:37  No: 90263

.NET  です。
ヘッダーのつもりで、一行目の左端にファイル名
右詰めに印刷日時を印刷したいのですが苦労しています。
まず、ファイル名だけでも右詰めに印刷しようと

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim headerString As String  = "ファイル名"
Dim headerFont As New Font("MS UI Gothic", 8)
Dim headerAreaSize As SizeF
headerAreaSize = e.Graphics.MeasureString(headerString, headerFont)

Dim fmt As New StringFormat
fmt.Alignment = StringAlignment.Far
fmt.LineAlignment = StringAlignment.Near

e.Graphics.DrawString( _
headerString, _
headerFont, _
Brushes.Black, _
New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Right, e.MarginBounds.Top + headerAreaSize.Height), _
fmt _
)

Dim pointL As New PointF(e.MarginBounds.Left, e.MarginBounds.Top + headerAreaSize.Height)
Dim pointR As New PointF(e.MarginBounds.Right, e.MarginBounds.Top + headerAreaSize.Height)
e.Graphics.DrawLine(New Pen(Color.Black, 1), pointL, pointR)

End Sub

これだとRectangleFの中に文字が入らず、右上から文字が始まります。
何処が間違っているのでしょうか?
また、両サイドに印刷するサンプルでも無いでしょうか?
よろしくお願いします。


白虎  2005-06-07 08:52:10  No: 90264

すみません
自己解決しました。

Dim rectHeader As New RectangleF( _
e.MarginBounds.Left, _
e.MarginBounds.Top, _
e.MarginBounds.Right - headerAreaSize.Width, _
e.MarginBounds.Top + headerAreaSize.Height _
)

正解じゃないかもしれませんが
これで、思うような印刷ができました。
スレ  汚してすみませんでした。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加