I want to Print a txt file with this code :
class Printing
{
PrintDocument prndoc = new PrintDocument() ;
PrintPreviewDia log ppd = new PrintPreviewDia log();
PrintDialog prn = new PrintDialog();
public Printing()
{
prndoc.PrintPag e += new PrintPageEventH andler(PrintPag e);
ppd.Document = prndoc;
prn.Document = prndoc;
prn.AllowSomePa ges = true;
prn.PrinterSett ings.FromPage = 1;
prn.PrinterSett ings.ToPage = prn.PrinterSett ings.MaximumPag e;
}
public void PrintPage(objec t obj, PrintPageEventA rgs e)
{
string strPrintText;
StreamReader strread = new StreamReader("C :\\Haftungsauss chluss.txt");
StringFormat strF = new StringFormat();
strPrintText = strread.ToStrin g();
Graphics grfx = e.Graphics;
Font font = new Font("Arial",30 0);
float cyFont = font.GetHeight( grfx);
RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(
e.MarginBounds. Left - (e.PageBounds.W idth - grfx.VisibleCli pBounds.Width)
/2,
e.MarginBounds. Top - (e.PageBounds.H eight - grfx.VisibleCli pBounds.Height)
/2,
e.MarginBounds. Width , e.MarginBounds. Height);
rectfText = RectangleF.Infl ate(rectfFull, 0,-2 * cyFont);
int iDisplayLines = (int) Math.Floor(rect fText.Height / cyFont);
rectfText.Heigh t = iDisplayLines * cyFont;
grfx.DrawString (strPrintText,f ont,Brushes.Bla ck,rectfText,st rF);
}
But how I start the Print Preview / Printing ??
class Printing
{
PrintDocument prndoc = new PrintDocument() ;
PrintPreviewDia log ppd = new PrintPreviewDia log();
PrintDialog prn = new PrintDialog();
public Printing()
{
prndoc.PrintPag e += new PrintPageEventH andler(PrintPag e);
ppd.Document = prndoc;
prn.Document = prndoc;
prn.AllowSomePa ges = true;
prn.PrinterSett ings.FromPage = 1;
prn.PrinterSett ings.ToPage = prn.PrinterSett ings.MaximumPag e;
}
public void PrintPage(objec t obj, PrintPageEventA rgs e)
{
string strPrintText;
StreamReader strread = new StreamReader("C :\\Haftungsauss chluss.txt");
StringFormat strF = new StringFormat();
strPrintText = strread.ToStrin g();
Graphics grfx = e.Graphics;
Font font = new Font("Arial",30 0);
float cyFont = font.GetHeight( grfx);
RectangleF rectfFull, rectfText;
rectfFull = new RectangleF(
e.MarginBounds. Left - (e.PageBounds.W idth - grfx.VisibleCli pBounds.Width)
/2,
e.MarginBounds. Top - (e.PageBounds.H eight - grfx.VisibleCli pBounds.Height)
/2,
e.MarginBounds. Width , e.MarginBounds. Height);
rectfText = RectangleF.Infl ate(rectfFull, 0,-2 * cyFont);
int iDisplayLines = (int) Math.Floor(rect fText.Height / cyFont);
rectfText.Heigh t = iDisplayLines * cyFont;
grfx.DrawString (strPrintText,f ont,Brushes.Bla ck,rectfText,st rF);
}
But how I start the Print Preview / Printing ??
Comment