Joza wrote:
Thanx Sean, now I know where to start, but here is another problem; do I must send some
printer esc sequences to printer? If so, what to do if I use several type of printers; for instance,
Epson, Fujitsu... I think that they use different esc seq. I'm asking that because I have created
report in Crystal Report, and report must be printed on A3 paper size. But printing is slow and
I cannot define properly page size through CR. I must use printers options in control panel to
set the page size but that is not good for my users because they do not know how to do that,
especially beacuse some of they have a Epson, some Fujitsu and other types... and for each
printer the options are different. So I must make something unviersal.
Hi Joza,
Not a problem, at all. The beauty of using the API is that you don't
have to worry about what language the printer speaks! Page size, etc.
is all provided to you by the classes.
As an example, try this:
1) Start a new VS Windows application
2) Add a TextBox and a Button control to the form
3) Add a PrintDocument component to the form
4) Add code to the buttons Click event handler to print the page. Your
code should look like this:
private void btnPrint_Click( object sender, EventArgs e)
{
printDocument1. Print();
}
5) Add code to the PrintDocuments PrintPage event and add code to handle
print event. Your code should look something like this (don't forget to
add your using directive for the System.Drawing. Printing namespace):
private void printDocument1_ PrintPage(objec t sender, PrintPageEventA rgs e)
{
// Create our default font
Font fnt = new Font("Arial", 10, FontStyle.Regul ar,
GraphicsUnit.Po int);
// Notice additional properties provided by PrintPageEventA rgs
e.Graphics.Draw String(txtMyTex t.Text, fnt, Brushes.Black, 0, 0);
e.HasMorePages = false;
}
To make things interesting, you might want to consider setting the
MultiLine property of the TextBox to true so that it supports more than
a single line of text. At any rate, however, this should print
something, regardless of the kind of printer you have.
One important thing to note is that the PrintPageEventA rgs class
provides MarginBounds and PageBounds properties that can be used to
specify the page settings that you desire.
Hope that helps,
--
Sean