Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load OpenFileDialog1.ShowDialog() TextBox1.Text = OpenFileDialog1.FileName ‘PrintDocument1.Print() print() End Sub Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.DrawString(TextBox1.Text, New Font("宋体", 20), New Pen(Color.Black, 1).Brush, 30, 30) e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(500, 500, 500, 500)) End Sub Sub print() Dim printdialog1 As New PrintDialog() ‘printdialog1.ShowDialog() ‘PrintDocument1 = OpenFileDialog1.FileName.ToString PrintDialog1.Document = PrintDocument1 Dim rusult As DialogResult = printdialog1.ShowDialog() If rusult = DialogResult.OK Then PrintDocument1.Print() End If End Sub End Class
时间: 2024-11-07 00:08:19