Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Printing in vb 2005
Author:
Sabith kp
E-mail:
Click to e-mail author
Website:
http://vb2008.blogspot.com
Submitted:
7/9/2007
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
String Manipulation
Views:
42123
I created this code for printing items from listview in my inventory software.
Declarations:
'none
Code:
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 Document s 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 'I Create above code for Printing Sale's and Purchase Data in my software.In vb 2005 printing is very easy.This is the one of the simple way to print in VB2005.if you want to learn detailed printing Tutorial and Vb2005 Source Codes then please visit: http://vb2008.blogspot.com
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement