473,382 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

HELP: Any Printing Guru's? (PrintPreview OK...PrintDoc... NOT!)

This is driving me NUTZ!!! I've been screwing around on this for a week now.
And I have tried to find examples similar to what I have (nada). Got lots of
streaming a TXT file... bah!

I am really stuck here (probably the ol' Not seeing the tree cause of the
forest thingy). But I just can not get this to work.

The following is my Test example code. Just needs a Button1 on a blank Form.
Add in PrintDocument1, PrintPreviewDialog1, PageSetupDialog1... and run it.

It does everything that I want it to... EXCEPT print! I get the multiple page
preview. My formating is okay. But all it prints is a Single Blank page with
my "Weeks Total Hours: " on the page... Why??? Why can I preview OK... but
not print?
MY Test CODE (watch for word wrap):

Imports System.IO
Imports System.Drawing.Printing
' ************************************************** *******************
' Print Out Variables
Dim itm, rowTtl As Integer
Dim rwCntr As Integer ' Print Rows Counter
Dim pageNo As Integer ' Page Number
Dim PtrCtr As Integer
Dim tableFont, tableFont1 As Font
Dim X1, X2, X3 As Integer
Dim W1, W2, W3 As Integer
Dim Y As Integer
Dim lbWeekItems As Integer = 30
' ************************************************** *******************

' ************************************************** *******************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal eg As
System.EventArgs) Handles Button1.Click

Dim pageWidth As Integer
PageSetupDialog1.PageSettings = PrintDocument1.DefaultPageSettings
PageSetupDialog1.AllowOrientation = False
PrintDocument1.DefaultPageSettings.Margins.Top = 75
PrintDocument1.DefaultPageSettings.Margins.Bottom = 50
PrintDocument1.DefaultPageSettings.Margins.Left = 50
PrintDocument1.DefaultPageSettings.Margins.Right = 50
PrintDocument1.DefaultPageSettings.Landscape = True

tableFont = New Font("Arial", 10)
tableFont1 = New Font("Arial", 9)

With PrintDocument1.DefaultPageSettings
pageWidth = .PaperSize.Height - _
.Margins.Left - _
.Margins.Right
' Measured in 1/100ths of an Inch
End With

PtrCtr = 0
rwCntr = 0
pageNo = 0

' X's are coordinates of the left edge of the columns
' W's are the widths of the columns
W1 = 75
W2 = 250
W3 = 40
X1 = 50
X2 = 410
X3 = 720

Try
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
Catch exc As Exception
MsgBox("Print Operation Failed... " & vbCrLf & exc.Message)
End Try

End Sub
' ************************************************** *******************
Protected Sub PrintDocHeader(ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
Dim str As String

Y = PrintDocument1.DefaultPageSettings.Margins.Top
str = "Time Sheet Header"
e.Graphics.DrawString(str, tableFont, Brushes.Black, X1, Y)
Y = Y + 25
e.Graphics.DrawString("Job Information", tableFont, Brushes.Black, X1, Y)
e.Graphics.DrawString("Cost Code Information", tableFont, Brushes.Black,
X2, Y)
e.Graphics.DrawString("Sat", tableFont, Brushes.Black, X3, Y)
e.Graphics.DrawString("Sun", tableFont, Brushes.Black, X3 + 40, Y)
e.Graphics.DrawString("Mon", tableFont, Brushes.Black, X3 + 80, Y)
e.Graphics.DrawString("Tue", tableFont, Brushes.Black, X3 + 120, Y)
e.Graphics.DrawString("Wed", tableFont, Brushes.Black, X3 + 160, Y)
e.Graphics.DrawString("Thr", tableFont, Brushes.Black, X3 + 205, Y)
e.Graphics.DrawString("Fri", tableFont, Brushes.Black, X3 + 245, Y)
e.Graphics.DrawString("Total", tableFont, Brushes.Black, X3 + 283, Y)
Y = Y + 20
' Draw Break Lines
With PrintDocument1.DefaultPageSettings
e.Graphics.DrawLine(Pens.Black, X1, Y, .PaperSize.Height - 50, Y)
e.Graphics.DrawLine(Pens.Black, X1, Y + 2, .PaperSize.Height - 50, Y +
2)
End With
Y = Y + 4

End Sub
' ************************************************** *******************
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e
As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

While PtrCtr < lbWeekItems
Dim str As String
rwCntr = rwCntr + 1

' Print Page Header
If rwCntr = 1 Then
PrintDocHeader(e)
' Print Page Number
pageNo = pageNo + 1
e.Graphics.DrawString("Page " & pageNo, tableFont, Brushes.Black,
1000, 800)
End If

Dim R1 As New RectangleF(X1, Y, W1, 80) ' Col 1 Job
Dim R2 As New RectangleF(X1 + 80, Y, W2, 80) ' Col 2 Job Desc
Dim R3 As New RectangleF(X2, Y, W1, 80) ' Col 3 cCode
Dim R4 As New RectangleF(X2 + 60, Y, W2, 80) ' Col 4 cCode Desc
Dim R5 As New RectangleF(X3, Y, W3, 80) ' Col 5 Sat
Dim R6 As New RectangleF(X3 + 40, Y, W3, 80) ' Col 6
Dim R7 As New RectangleF(X3 + 80, Y, W3, 80) ' Col 7
Dim R8 As New RectangleF(X3 + 120, Y, W3, 80) ' Col 8 Tue
Dim R9 As New RectangleF(X3 + 160, Y, W3, 80) ' Col 9
Dim R10 As New RectangleF(X3 + 205, Y, W3, 80) ' Col 10
Dim R11 As New RectangleF(X3 + 245, Y, W3, 80) ' Col 11 Fri
Dim R12 As New RectangleF(X3 + 285, Y, W3, 80) ' Col 12 Total
Dim R13 As New RectangleF(X1, Y + 17, 1050, 80) ' Col 13 cCode Desc

str = "Item"
e.Graphics.DrawString(str, tableFont, Brushes.Black, R1)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R2)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R3)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R4)

' Week Day Hours
str = lbWeekItems
e.Graphics.DrawString(str, tableFont, Brushes.Black, R5)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R6)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R7)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R8)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R9)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R10)
e.Graphics.DrawString(str, tableFont, Brushes.Black, R11)
e.Graphics.DrawString("22", tableFont, Brushes.Black, R12)
Y = Y + 15

str = "Line Item: " & lbWeekItems
If Len(str) <= 165 Then
tableFont1 = New Font("Arial", 9)
Else
tableFont1 = New Font("Arial", 8)
End If
e.Graphics.DrawString(str, tableFont1, Brushes.Black, R13)
' Reset Font
tableFont1 = New Font("Arial", 9)

' Draw Break Line
With PrintDocument1.DefaultPageSettings
Y = Y + 20
e.Graphics.DrawLine(Pens.Black, X1, Y, .PaperSize.Height - 50, Y)
End With

' That's it for this page...
If rwCntr = 18 Then
e.HasMorePages = True
PtrCtr = PtrCtr + 1
rwCntr = 0
Exit Sub
End If
PtrCtr = PtrCtr + 1
End While

' Total Weeks Hours (last page)
With PrintDocument1.DefaultPageSettings
e.Graphics.DrawString("Weeks Total Hours: ", tableFont, Brushes.Black,
875, 775)
e.Graphics.DrawString("44", tableFont, Brushes.Black, 1000, 775)
End With

' No More Pages to Print
e.HasMorePages = False

End Sub
' ************************************************** *******************

Any kind soul can spot the trouble?

Regards,

Bruce
Nov 20 '05 #1
0 1037

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mario | last post by:
Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page:...
5
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am...
0
by: Nigel | last post by:
I successfully create a .NET Component (Visual Basic .NET) that would print, unfortunately when used within a web browser it appears that .NET security doesn't allow you to run code that interacts...
2
by: Kevin | last post by:
In my VB2005 Windows Forms program I want to be able to click a button and have my Dot Matrix printer print one 15/16 x 3 1/2 address label from continuous forms. I'm trying to use a...
1
by: Marc | last post by:
Hi, I am setting up a orint function that prints the screen area. It is all working except my screen area spans two print pages hwne viewed using a print preview dialogue . I am trying to fnd a...
3
by: jonathan184 | last post by:
script is printing output correct but not the actual output. Basically what the script is doing it taking a 1 flat file then it is splits the file into smaller files in 1000 record increments ...
1
by: byquestion | last post by:
Hi there xslt gurus, i am kinda new to xslt and having difficulty to implement my some iterations. i need to recreate an xml file by using xslt. here is the sample xml file(input for xslt) ...
0
by: vench | last post by:
Hi! I have a vb.net project that uses mozilla activeX control, there is no problem in navigating or loading the url in the control, the problem that I have encountered is when printpreview using the...
0
by: rafiki31 | last post by:
I have been hitting walls trying to find the right way to print from a web application. Here is the thing, im implementing a webapplication for a kiosk. The kiosk has its own card printer. When i...
0
by: bschomp | last post by:
Hi, when I try to print from my richtextbox it's not printing what I have typed in. I want to be able to print the image that it shows. So if I type in Hello World it will print out Hello World. This...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.