Imports System.Drawing.Printing
Public Class Form1
Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
' إعداد الطابعة
Dim printDoc As New PrintDocument()
' إعداد حجم الصفحة
AddHandler printDoc.BeginPrint, AddressOf printDoc_BeginPrint
AddHandler printDoc.PrintPage, AddressOf printDoc_PrintPage
' عرض إعدادات الطباعة للمستخدم (اختياري)
Dim printDialog As New PrintDialog()
printDialog.Document = printDoc
If printDialog.ShowDialog() = DialogResult.OK Then
printDoc.Print()
End If
End Sub
Private Sub printDoc_BeginPrint(sender As Object, e As PrintEventArgs)
Dim printDoc As PrintDocument = CType(sender, PrintDocument)
' تعيين حجم الصفحة للورقة المطلوبة
Dim pageSize As New PaperSize("Custom", 1200, 400) ' 12 سم × 4 سم (بالبكسل، حيث 1 سم = 100 بكسل تقريبًا)
printDoc.DefaultPageSettings.PaperSize = pageSize
printDoc.DefaultPageSettings.Landscape = False
End Sub
Private Sub printDoc_PrintPage(sender As Object, e As PrintPageEventArgs)
' تحديد إعدادات الطباعة
Dim font As New Font("Arial", 16)
Dim brush As New SolidBrush(Color.Black)
Dim text As String = "منتدى فيجوال بيسك"
' رسم النص على الصفحة
e.Graphics.DrawString(text, font, brush, New PointF(10, 10)) ' 10, 10 هي الإحداثيات لتحديد مكان النص
End Sub
End Class