|
-
Jan 6th, 2006, 06:00 AM
#1
Thread Starter
Member
Send a string to the printer
Hi,
I have the following code that prints me the text that I defined.
(That's a pice of code that I have modified.)
In this moment when I run the code it prints only one page, cutting the rest.
How can I know if there are another pages to print and print them?
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
//pt printare
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
namespace WindowsApplication1
{
public class PrintingExample : System.Windows.Forms.Form
{
private Font printFont;
private string text_de_tiparit;
public PrintingExample(string text)
: base()
{
// The Windows Forms Designer requires the following call.
//InitializeComponent();
text_de_tiparit = text;
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Print each line of the file.
//while (count < linesPerPage &&
//((line = streamToPrint.ReadLine()) != null))
//{
line = text_de_tiparit;
yPos = topMargin; // + (count *
//printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
//count++;
//}
// If more lines exist, print another page.
//if (line != null)
//ev.HasMorePages = true;
//else
//ev.HasMorePages = false;
}
// This is the main entry point for the application.
public static void Main(string[] args)
{
string text_de_tiparit = "a\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\na\nb\nc\n";
Application.Run(new PrintingExample(text_de_tiparit));
}
}
}
Thanks
Last edited by neptun_; Jan 6th, 2006 at 10:36 AM.
-
Jan 7th, 2006, 12:35 AM
#2
Re: Send a string to the printer
You've commented out the part that controls whether more pages are printed or not:
Code:
// If more lines exist, print another page.
//if (line != null)
//ev.HasMorePages = true;
//else
//ev.HasMorePages = false;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|