Imports System.Globalization Imports System.Drawing.Printing Imports System.Drawing Class MainWindow Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. AddHandler printDocument1.PrintPage, AddressOf printDocument1_PrintPage End Sub 'Declaration the global variables Private paperSize As New PaperSize("papersize", 300, 500) 'set the paper size Private totalnumber As Integer = 0 'this is for total number of items of the list or array Private itemperpage As Integer = 0 'this is for no of item per page Private printDocument1 As New PrintDocument() Private printDialog1 As New System.Windows.Forms.PrintDialog() Private DefaultFont As New Font("Calibri", 20) Private Sub Button_Click(sender As Object, e As RoutedEventArgs) If txtStart.Text Then itemperpage = 1 totalnumber = txtStart.Text printDialog1.Document = printDocument1 printDocument1.DefaultPageSettings.PaperSize = paperSize printDialog1.ShowDialog() 'printDocument1.PrinterSettings.PrinterName = ""; printDocument1.Print() Else MessageBox.Show("Invalid number") End If End Sub Private Function CheckNumber(str As String) As Boolean Dim Num As Double Return Double.TryParse(str, Num) End Function 'Define the Printpage event of the printdocument Private Sub printDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Dim currentY As Single = 10 While totalnumber <= txtStart.Text ' check the number of items e.Graphics.DrawString("J" + totalnumber.ToString("000000", CultureInfo.InvariantCulture), DefaultFont, System.Drawing.Brushes.Black, 50, currentY) 'print each item currentY += 20 ' set a gap between every item totalnumber += 1 'increment count by 1 If itemperpage < 1 Then ' check whether the number of item(per page) is more than 1 or not itemperpage += 1 ' increment itemperpage by 1 ' set the HasMorePages property to false , so that no other page will not be added e.HasMorePages = False Else ' if the number of item(per page) is more than 1 then add one page itemperpage = 1 'initiate itemperpage to 0 . If totalnumber <= C> XAML Code <pre lang="HTML"><Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="175" Width="303"> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="1.5*" /> </Grid.ColumnDefinitions> <Label C/> <TextBox x:Name="txtStart" Grid.Column="1" /> <Button Grid.Row="2" Grid.ColumnSpan="2" C/> </Grid> </Window>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)