wasim

wasim

  • NA
  • 4
  • 0

Printing Listview in Vb Express 2008

Dec 20 2009 7:53 PM

I am using Vb express 2008 with MsAccess as database.
I am working on a point of sales system and now i am on the printing stage. I tried to implement the code in a good article of this site PRINTING LISTVIEW IN VB 2005. But i am having problems with the implementation of this code:
The actual code is as under:

'Printing in VB 2005 Printing Data From ListView

Imports System.Drawing.Printing

Dim tableFont, titlefont, headfont As Font
Dim X1, X2, X3 As Integer
Dim
W1, W2, W3 As Integer
Dim
Y As Integer
Dim
itm As Integer

'I Create this Sub for set the Fontname,FontSize,Paper Setting

Public Sub PrintBIll()

Dim PSize As Integer = ListItems.Items.Count
Dim PHi As Double
With
PrintDocument1.DefaultPageSettings
Dim Ps As PaperSize
PHi = PSize * 20 + 350
Ps = New PaperSize("Cust", 800, PHi).Margins.Top = 15.Margins.Bottom = 20.PaperSize = Ps
End With

headfont = New Font("Courier New", 16, FontStyle.Bold)
tableFont = New Font("Courier New", 10)
titlefont = New Font("Courier New", 12, FontStyle.Bold)
X1 = PrintDocument1.DefaultPageSettings.Margins.Left
Dim pageWidth As Integer
With
PrintDocument1.DefaultPageSettings pageWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
End With
X2 = X1 + 120
X3 = X2 + pageWidth * 0.5
W1 = X2 - X1
W2 = X3 - X2
W3 = pageWidth - X3

'If u want to print Directly then

PrintDocument1.Print()

'Elseif u want print after print preview then u pls use this code

PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
itm = 0

End Sub

'==============================================

'Printing Current Documents

 

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles

    PrintDocument1.PrintPage()

Y = PrintDocument1.DefaultPageSettings.Margins.Top + 10 e.Graphics.DrawString("INVOICE", headfont, Brushes.Black, X1 + 250, Y)

    e.Graphics.DrawString("Cash/Credit Bill ", titlefont, Brushes.Black, X1, Y + 50)

    e.Graphics.DrawString("To : " & txtCustomername.Text, titlefont, Brushes.Black, X1, Y + 80)

    e.Graphics.DrawString("Date : " & Format(DTsale.Value, "dd-MM-yyyy"), titlefont, Brushes.Black, X1 + 450, Y + 25)

    e.Graphics.DrawString("Bill No : " & txtReference.Text, titlefont, Brushes.Black, X1 + 450, Y + 50)

    Y = PrintDocument1.DefaultPageSettings.Margins.Top + 120

    With PrintDocument1.DefaultPageSettings

          e.Graphics.DrawLine(Pens.Black, .Margins.Left, Y + 20, _ .PaperSize.Width - .Margins.Right, Y + 20)

    End With

e.Graphics.DrawString("SNO", titlefont, Brushes.Black, X1, Y) e.Graphics.DrawString("NAME", titlefont, Brushes.Black, X2 - 50, Y)

    e.Graphics.DrawString("QTY", titlefont, Brushes.Black, X2 + 220, Y)

    e.Graphics.DrawString("RATE", titlefont, Brushes.Black, X2 + 280, Y)

    e.Graphics.DrawString("MRP", titlefont, Brushes.Black, X2 + 345, Y)

    e.Graphics.DrawString("TOTAL", titlefont, Brushes.Black, X2 + 425, Y)

    Y = Y + 30

    While itm < ListItems.Items.Count

        Dim str As String

        'str = ListItems.Items(itm).Text

        e.Graphics.DrawString(itm + 1, tableFont, Brushes.Black, X1, Y)

        str = ListItems.Items(itm).SubItems(1).Text

        Dim R As New RectangleF(X2 - 50, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, R)

        str = ListItems.Items(itm).SubItems(4).Text

        Dim k As New RectangleF(X2 + 220, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, k)

        str = ListItems.Items(itm).SubItems(5).Text

        Dim M As New RectangleF(X2 + 235, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, M)

        str = Format(ListItems.Items(itm).SubItems(7).Text, "Fixed")

        Dim N As New RectangleF(X2 + 280, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, N)

        '''''' str = Format(ListItems.Items(itm).SubItems(6).Text, "Fixed")

        Dim L As New RectangleF(X2 + 340, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, L)

        str = SetSpacing(Format(ListItems.Items(itm).SubItems(8).Text, "Fixed"), 10)

        Dim O As New RectangleF(X2 + 400, Y, W2, 80)

        e.Graphics.DrawString(str, tableFont, Brushes.Black, O)

        Dim lines, Cols As Integer

        e.Graphics.MeasureString(str, tableFont, New SizeF(W2, 50), _ New StringFormat(), Cols, lines)

        Dim Yc As Integer

        Yc = Y

        Y = Y + lines * tableFont.Height + 5

        Y = Math.Max(Y, Yc)

        itm = itm + 1

    End While

    e.Graphics.DrawString("Net Amount : " & SetSpacing(Format(txtNetAmount.Text, "Fixed"), 10), titlefont, Brushes.Black, X2 + 240, Y + 15)

    e.Graphics.DrawString("Roundof : " & SetSpacing(Format(txtRounof.Text, "Fixed"), 10), titlefont, Brushes.Black, X2 + 240, Y + 35)

    e.Graphics.DrawString("Paid Amount : " & SetSpacing(Format(txtPaymentAmount.Text, "Fixed"), 10), titlefont, Brushes.Black, X2 + 240, Y + 55)

    e.Graphics.DrawString("Balance : " & SetSpacing(Format(txtbalance.Text, "Fixed"), 10), titlefont, Brushes.Black, X2 + 240, Y + 75)

    e.Graphics.DrawString("", titlefont, Brushes.White, X2 + 240, Y + 105)

 

End Sub
While implementing the above code i am encountering follwoing problems in code:
Ps =
New PaperSize("Cust", 800, PHi).Margins.Top = 15.Margins.Bottom = 20.PaperSize = Ps
the error is: Margins is not member of System.Drawing.Printing.Papersize
str = Spacing(Format(Listitems.Items(itm).SubItems(8).Text,
"Fixed"), 10)
the error is: Spacing is not declared.
Please advise how i can implement the above code in VB express 2008 successfully.
Thanks