Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PrintDocument1.Print() End Sub Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim report As New MyReport report.Draw(e.Graphics) End Sub End Class
Public Class MyReport Public Sub Draw(g As Graphics) Dim rect As New Rectangle(20, 10, 200, 150) Dim gradientBrush As New Drawing2D.LinearGradientBrush(rect, Color.Blue, Color.Red, 0) g.FillRectangle(gradientBrush, 20, 10, 200, 150) End Sub End Class
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PrintDocument1.Print() End Sub Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown ReportModule.ReportDocument = Me.PrintDocument1 End Sub End Class
Imports System.Drawing.Printing Public Module ReportModule Public WithEvents ReportDocument As PrintDocument Private Sub ReportDocument_PrintPage(sender As Object, e As PrintPageEventArgs) Handles ReportDocument.PrintPage Dim rect As New Rectangle(20, 10, 200, 150) Dim gradientBrush As New Drawing2D.LinearGradientBrush(rect, Color.Blue, Color.Red, 0) e.Graphics.FillRectangle(gradientBrush, 20, 10, 200, 150) End Sub End Module