Printing/Print Preview Problem

  • Thread starter Thread starter Pkant
  • Start date Start date
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 ??
 
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
 
Hi,

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