By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Printing through CODE

P: n/a
First, let me tell you what I do NOT want.

1) To print a document.

2) To click on ANYTHING

Now, how do I print to a printer? It seems that I need
PrintPageEventArgs to print to a printer. Let me make
this simple.

Public Sub Main()

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Terish,
I take you want to send output to a printer, correct? Are you wanting to
write directly to the printer bypassing the Windows print driver?

Or would you like Windows to handle the formatting for you?

If you want Windows to handle the formatting you need to use the
PrintDocument class that I identified in my earlier post.

Remember Windows considers any output sent to the printer to be printed a
Document. Hence the name PrintDocument for the class. It has nothing really
to do with file 'Documents' such as Word.

The links I gave you include samples along with the explanation of how it
works.

Hope this helps
Jay

"TerishD" <te*****@adnd.com> wrote in message
news:11****************************@phx.gbl...
First, let me tell you what I do NOT want.

1) To print a document.

2) To click on ANYTHING

Now, how do I print to a printer? It seems that I need
PrintPageEventArgs to print to a printer. Let me make
this simple.

Public Sub Main()

Nov 20 '05 #2

P: n/a
No Modify? This thing took off and posted on its own.
Anyway, to continue.

Public sub MainRout()
dim I as integer
dim S(10) as string
S(0)="Red"
S(1)="Green"
S(2)="Blue"
I=int(rnd*3)

PrintToPrinter(S(I)) 'HOW DO I DO THIS??????????????

End sub

'Note, the below routine was stolen from previous
<i>Help</i>, but cannot be called from inside code.

Public Sub pd_PrintPage(ByVal sender As Object, ByVal ev
As PrintPageEventArgs)
Dim LnPPg As Single = 0
Dim pfnt As Font
Dim MrgnL As Single = ev.MarginBounds.Left
Dim MrgnT As Single = ev.MarginBounds.Top
Dim SL As String = Nothing

' Calculate the number of lines per page.
PFnt = New Font(FtNm, FtSz)
LnPPg = ev.MarginBounds.Height / PFnt.GetHeight
(ev.Graphics)
' Iterate over the file, printing each line.

ev.Graphics.DrawString(SP, PFnt, Brushes.Black,
MrgnL, PY, New StringFormat())

' If more lines exist, print another page.
If Not (SL Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub


Nov 20 '05 #3

P: n/a
First thanks, you are being helpful.

Now, let me rephrase my question. I actually figured how
to get things to print. So now, the question is

How does Microsoft expect me to set up a page to be
printed? The thing is printing one line to a page, and
there seems to be no way to tell it that all those lines
go on the same page.

Nov 20 '05 #4

P: n/a
TerishD,
Assuming you are using the print event, you need to draw each line in one
event.

Use a for each loop in your print event, to draw each line of text,
increasing the y by the height of the line. You can use
Graphics.MeasureString to get the size of a line.

This example is based on printing a DataSet, however it should give you
ideas how to arrange information for anything you want to print.

http://msdn.microsoft.com/library/de...et01282003.asp

Hope this helps
Jay

"TerishD" <te*****@adnd.com> wrote in message
news:06****************************@phx.gbl...
First thanks, you are being helpful.

Now, let me rephrase my question. I actually figured how
to get things to print. So now, the question is

How does Microsoft expect me to set up a page to be
printed? The thing is printing one line to a page, and
there seems to be no way to tell it that all those lines
go on the same page.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.