Public Class Form1 ''' <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) Using font As Font = New Font("MS 明朝", 10) Using pen As New Pen(Brushes.Black, 1) Using g As Graphics = Graphics.FromImage(report) '●1.全体設定 Dim locate As Point = New Point(1, 1) g.Clear(Color.White) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias g.DrawRectangle(pen, New Rectangle(locate, New Size(size.Width - 2, size.Height - 2))) '●2.ヘッダー部 Dim nameTitle As String = Fit("氏名", 12, LeftRightAlignment.Left) Dim postTitle As String = Fit("郵便番号", 12, LeftRightAlignment.Left) Dim adrsTitle As String = Fit("住所", 25, LeftRightAlignment.Left) Dim yearTitle As String = Fit("年齢", 4, LeftRightAlignment.Right) Dim sexTitle As String = Fit("性別", 4, LeftRightAlignment.Right) Dim title As String = nameTitle & postTitle & adrsTitle & yearTitle & sexTitle g.DrawString(title, font, Brushes.Black, locate) '●3.明細部 '▼3-1.行間計算等 Dim pitch As Integer = font.Height + 3 Dim maxrow As Integer = size.Height / pitch Dim rowcounter As Integer = 0 Do While rowcounter < maxrow '▼3-2.罫線 locate = New Point(1, rowcounter * pitch + pitch) g.DrawLine(pen, locate, New Point(size.Width - 2, locate.Y)) '▼3-3.明細内容 If rowcounter < data.Rows.Count Then Dim row As DataRow = data.Rows(rowcounter) Dim Name As String = Fit(row(0), 12, LeftRightAlignment.Left) Dim post As String = Fit(row(1), 12, LeftRightAlignment.Left) Dim adrs As String = Fit(row(2), 25, LeftRightAlignment.Left) Dim year As String = Fit(row(3), 4, LeftRightAlignment.Right) Dim sex As String = Fit(row(4), 4, LeftRightAlignment.Right) Dim line As String = Name & post & adrs & year & sex g.DrawString(line, font, Brushes.Black, locate) End If rowcounter += 1 Loop End Using End Using End Using Return report End Function