Printing/Print Preview Problem

P

Pkant

I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument();

PrintPreviewDialog ppd = new PrintPreviewDialog();

PrintDialog prn = new PrintDialog();



public Printing()

{

prndoc.PrintPage += new PrintPageEventHandler(PrintPage);

ppd.Document = prndoc;

prn.Document = prndoc;


prn.AllowSomePages = true;

prn.PrinterSettings.FromPage = 1;

prn.PrinterSettings.ToPage = prn.PrinterSettings.MaximumPage;

}



public void PrintPage(object obj, PrintPageEventArgs e)

{


string strPrintText;

StreamReader strread = new StreamReader("C:\\Haftungsausschluss.txt");

StringFormat strF = new StringFormat();

strPrintText = strread.ToString();


Graphics grfx = e.Graphics;

Font font = new Font("Arial",300);

float cyFont = font.GetHeight(grfx);

RectangleF rectfFull, rectfText;


rectfFull = new RectangleF(

e.MarginBounds.Left - (e.PageBounds.Width - grfx.VisibleClipBounds.Width)
/2,

e.MarginBounds.Top - (e.PageBounds.Height - grfx.VisibleClipBounds.Height)
/2,

e.MarginBounds.Width , e.MarginBounds.Height);

rectfText = RectangleF.Inflate(rectfFull, 0,-2 * cyFont);


int iDisplayLines = (int) Math.Floor(rectfText.Height / cyFont);

rectfText.Height = iDisplayLines * cyFont;

grfx.DrawString(strPrintText,font,Brushes.Black,rectfText,strF);


}

But how I start the Print Preview / Printing ??
 
L

Luc Kumps

Pkant said:
I want to Print a txt file with this code :

class Printing

{

PrintDocument prndoc = new PrintDocument();

PrintPreviewDialog ppd = new PrintPreviewDialog();

PrintDialog prn = new PrintDialog();


But how I start the Print Preview / Printing ??

ppd.ShowDialog();
prn.ShowDialog();

// Luc K
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

There's also a PrintController class (it has several species). I beleive
this is the class that controls the printing process.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top