Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myp.InvalidatePreview()
    End Sub

    Private Sub myp_PrintDocument() Handles myp.PrintDocument
        myp.NewPage()
        Dim num As Integer
        num = Val(TextBox4.Text)
        Dim ls As Integer
        ls = Val(TextBox3.Text)
        Dim sum As Integer = 0
        Dim lwidth As Single
        Dim lheight As Single
        lwidth = myp.ConvFromDisplay(Panel1.Width, True)
        lheight = myp.ConvFromDisplay(Panel1.Height, False)
        Dim tempy As Single

        Do While sum < num
            If myp.IsNewPage(lheight) = True Then
                myp.NewPage()
            End If
            myp.Currentx = 0
            tempy = myp.Currenty
            For i As Integer = 1 To ls
                myp.Currenty = tempy
                TextBox1.Text = CStr(sum)
                myp.DrawPanel(Panel1, False)
                myp.Currentx = lwidth * i
                sum = sum + 1
                If sum >= num Then
                    Exit For
                End If
            Next

        Loop

    End Sub


End Class
