i'm trying to make price lable printer and i was able to print a single page
for a single id, but my problem is when i'm trying to print more that one id
i was not able to make it work, i'm still learning but i was hoping that someone can
give me idea how to make it work

Imports MySql.Data.MySqlClient

Public Module thisModule
'Info for the Price Lable
Public NameV As String
Public IdV As String
Public DiscV As String
Public ArDiscV As String
Public PriceV As String
Public SalesPriceV As String
End Module

Public Class Form1
Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=inven")

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    For Each s As String In Me.SearchB.Lines

        Dim nextLineText As String = s
        _lineCount = SearchB.Lines.Length
        _endPages = _lineCount
        'MsgBox(_endPages)

        Dim command As New MySqlCommand("SELECT * FROM `items` WHERE `id` = @id", connection)
        command.Parameters.Add("@id", MySqlDbType.String).Value = s

        Dim reader As MySqlDataReader
        If SearchB.Text IsNot "" Then 'If SeachBox is empty then do nothing

            connection.Open()

            reader = command.ExecuteReader()

            If reader.Read() Then

                thisModule.NameV = reader(1)
                thisModule.IdV = reader(0)
                thisModule.DiscV = reader(2)
                thisModule.ArDiscV = reader(3)
                thisModule.PriceV = reader(4)
                thisModule.SalesPriceV = reader(5)

                PrintPreviewControl1.Document = PrintDocument1

                PrintPB.Visible = True
            ElseIf SearchB.Text = "" Then
                MsgBox("Please enter Model")
            End If

            connection.Close()

        End If 'End SeachBox
    Next
End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim font As New Font("Arial", 30, FontStyle.Bold)
    Dim WarrEng As New Font("Arial", 18, FontStyle.Bold)
    Dim WarrArb As New Font("Arial", 28, FontStyle.Bold)
    Dim SalesFont As New Font("Arial", 70, FontStyle.Strikeout Or FontStyle.Bold)
    Dim PriceS As New Font("Arial", 70, FontStyle.Bold)

    If A4C.Checked Then
        Dim newImage As Image = Image.FromFile("C:\Users\GAMING PC\Desktop\ElecPrice\A4.png") 'A4 Image
        e.Graphics.DrawImage(newImage, 0, 0) 'A4 Image Location
        'e.Graphics.DrawString(thisModule.NameV, font, Brushes.Black, 65, 400)
        e.Graphics.DrawString(thisModule.NameV + "  " + thisModule.IdV, font, Brushes.Black, 65, 350)
        e.Graphics.DrawString(thisModule.DiscV, font, Brushes.Black, 130, 450)
        e.Graphics.DrawString(thisModule.ArDiscV, font, Brushes.Black, 600, 450)
        e.Graphics.DrawString(thisModule.PriceV, PriceS, Brushes.White, 510, 110)

    ElseIf A4P.Checked Then
        Dim newImage As Image = Image.FromFile("C:\Users\GAMING PC\Desktop\ElecPrice\A4Promo.png") 'A4-Promo Image
        e.Graphics.DrawImage(newImage, 0, 0) 'A4 Image Location
        'e.Graphics.DrawString(thisModule.NameV, font, Brushes.Black, 65, 400)
        e.Graphics.DrawString(thisModule.NameV + "  " + thisModule.IdV, font, Brushes.Black, 65, 350)
        e.Graphics.DrawString(thisModule.DiscV, font, Brushes.Black, 130, 450)
        e.Graphics.DrawString(thisModule.ArDiscV, font, Brushes.Black, 600, 450)
        e.Graphics.DrawString(thisModule.PriceV, SalesFont, Brushes.Black, 25, 650)
        e.Graphics.DrawString(thisModule.SalesPriceV, PriceS, Brushes.White, 510, 110)

    End If

    If WRT.Checked = True Then

        e.Graphics.DrawString("Extended warranty available on this item..Please refer to sales team", WarrEng, Brushes.Red, 10, 890)

    Else
        e.Graphics.DrawString("", font, Brushes.Black, 65, 500)

    End If

End Sub

End Class

I'm going to answer how I might go about this. Since you have a method to get one print out, then you would step back one step to build a loop to repeat that printout but one for each item in some list or what have you. Just like any machine that makes something, to make more you repeat that over and over till done.

commented: your idea are great and it work, but i'm trying to Preview the Price label before printing them +0

So you now have a way to print more than one lable but I bet you want to preview a screen full of different labels before printing. For that you are going to have to change your thought pattern.

Long ago, we would print labels and did not use the print preview but just showed on screen the data that would print. So you could instead make up some screen with text boxes (?) and fill those with the data you are really going to print. I take it the reason for the preview is to check prices, text, etc. and not type setting.

commented: I did as you advice and i change my pattern, and i was able to preview more than 1 label thank you for support :) +0

In cases where I need to check my printouts I have installed a virtuel pdf printer and print to this one before committing to paper. I use Cute PDF Writer on these occasions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.