Visual Basic 中学校 掲示板 投稿の管理
タグのない投稿を抽出
統計
RSS
Visual Basic 中学校
投稿一覧
印刷処理で列項目とデータを整列させて出力したいです。
この投稿へのリンク
https://keijiban.umayadia.com/ThreadDetail.aspx?ThreadId=11231#CommentId25472
この投稿の削除
削除パスワード
削除する
コメント本文
投稿者
たかくん
 (社会人)
投稿日時
2013/3/30 17:39:05
こんにちは、お世話になります。
下記のコードは顧客情報の抽出結果を印刷する時のメソッドなのですが項目とデータが綺麗に表示
できず困ってます。
Shift_JISに変換してみたもののまだガタガタの表示になってます。
各項目事にPadding()しているのですがどうもうまくいかないです。
どうすれば綺麗に表示できるでしょうか?
解る方よろしくお願いします。
''' <summary>
''' 帳票描画
''' </summary>
''' <param name="size">印刷可能範囲</param>
''' <returns>帳票画像</returns>
''' <remarks></remarks>
Private Function DrawReport(ByVal size As Size, ByVal data As DataTable) As Bitmap
Dim report As New Bitmap(size.Width, size.Height)
Try
Using font As Font = New Font("MS 明朝", 10)
Using pen As New Pen(Brushes.Black, 1)
Using g As Graphics = Graphics.FromImage(report)
Dim pitch As Integer = font.Height + 3
Dim maxrow As Integer = size.Height / pitch
Dim rowcounter As Integer = 0
Dim locate As Point = New Point(1, 1)
Dim strlist As String() = New String() {"氏名", "郵便番号", "住所", "年齢", "性別"}
Dim bytedata As List(Of Byte()) = Me.ChangeShift_JisEncoding(strlist)
Dim count As List(Of Integer) = Me.GetByteCount(strlist)
Dim datalist As List(Of String) = Me.ChangeShift_JisString(bytedata)
Dim name As String = datalist(0).PadRight(12 - count(0), " ")
Dim post As String = datalist(1).PadRight(12 - count(1))
Dim adrs As String = datalist(2).PadRight(25 - count(2), " ")
Dim year As String = datalist(3).PadLeft(4 - count(3))
Dim sex As String = datalist(4).PadLeft(4 - count(4))
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.DrawRectangle(pen, New Rectangle(locate, New Size(size.Width - 2, size.Height - 2)))
Dim title As String = name + post + adrs + year + sex
g.DrawString(Title, font, Brushes.Black, locate)
Do While rowcounter < maxrow
locate = New Point(1, rowcounter * pitch + pitch)
g.DrawLine(pen, locate, New Point(size.Width - 2, locate.Y))
If rowcounter < data.Rows.Count Then
strlist(0) = data(rowcounter)("Naming").ToString.Trim
strlist(1) = data(rowcounter)("PostalNo").ToString.Trim
strlist(2) = data(rowcounter)("Address").ToString.Trim
strlist(3) = data(rowcounter)("Year").ToString.Trim
strlist(4) = data(rowcounter)("Sex").ToString.Trim
bytedata = Me.ChangeShift_JisEncoding(strlist)
count = Me.GetByteCount(strlist)
datalist = Me.ChangeShift_JisString(bytedata)
name = datalist(0).ToString.PadRight(12 - count(0), " ")
post = datalist(1).ToString.PadRight(12 - count(1))
adrs = datalist(2).ToString.PadRight(25 - count(2), " ")
year = datalist(3).ToString.PadLeft(4 - count(3))
sex = datalist(4).ToString.PadLeft(4 - count(4))
Dim row As String = name + post + adrs + year + sex
g.DrawString(row, font, Brushes.Black, locate)
End If
rowcounter += 1
Loop
End Using
End Using
End Using
Catch ex As Exception
Log(ex, "CustomerSearchFormClass->DrawReport()")
End Try
Return report
End Function