Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PrintPreviewDialog1.Document = PrintDocument1
PrintDialog1.Document = PrintDocument1
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Randomize()
Dim count(25) As Integer
Dim MyGraphics As Graphics = e.Graphics
Dim MyPen1 As New Pen(Color.Blue, 1)
Dim MyPen2 As New Pen(Color.Red, 1)
Dim MyFont As New Font("標階體", 20)
Dim MyFont2 As New Font("標階體", 10)
Dim MyBrush As New SolidBrush(Color.Blue)
Dim ans As String = ""
Dim i, j As Integer
For i = 1 To 25
count(i) = Int(Rnd() * 61) + 40
Next
For i = 1 To 6
MyGraphics.DrawLine(MyPen1, 50, i * 50, 300, i * 50)
MyGraphics.DrawLine(MyPen1, i * 50, 50, i * 50, 300)
Next
For i = 1 To 5
For j = 1 To 5
MyGraphics.DrawString((i - 1) * 5 + j, MyFont, MyBrush, i * 50 + i, j * 50)
If count((i - 1) * 5 + j) < 60 Then
MyGraphics.DrawEllipse(MyPen2, i * 50, j * 50, 50, 50)
End If
Next
Next
For i = 1 To 25
ans = ans & count(i) & ","
Next
MyGraphics.DrawString(ans, MyFont2, MyBrush, 50, 310)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim MyGraphics As Graphics = e.Graphics
Dim MyPen1 As New Pen(Color.Blue, 1)
Dim MyFont As New Font("標階體", 20)
Dim MyBrush As New SolidBrush(Color.Blue)
Dim i, j As Integer
Dim count As Integer = 0
For i = 1 To 6
MyGraphics.DrawLine(MyPen1, 50, i * 50, 300, i * 50)
MyGraphics.DrawLine(MyPen1, i * 50, 50, i * 50, 300)
Next
For i = 1 To 5
For j = 1 To 5
MyGraphics.DrawString((i - 1) * 5 + j, MyFont, MyBrush, i * 50 + i, j * 50 + i)
Next
Next
End Sub
End Class |