Printing/Print Preview Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pkant

    #1

    Printing/Print Preview Problem

    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 ??






  • Luc Kumps

    #2
    Re: Printing/Print Preview Problem


    "Pkant" <pkant@isc-greiner.de> wrote in message
    news:uyJKSMngDH A.632@TK2MSFTNG P10.phx.gbl...[color=blue]
    > 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();
    >
    >
    > But how I start the Print Preview / Printing ??[/color]

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

    // Luc K



    Comment

    • Dmitriy Lapshin [C# / .NET MVP]

      #3
      Re: Printing/Print Preview Problem

      Hi,

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

      --
      Dmitriy Lapshin [C# / .NET MVP]
      X-Unity Test Studio

      Bring the power of unit testing to VS .NET IDE

      "Pkant" <pkant@isc-greiner.de> wrote in message
      news:uyJKSMngDH A.632@TK2MSFTNG P10.phx.gbl...[color=blue]
      > 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 ??
      >
      >
      >
      >
      >
      >[/color]

      Comment

      Working...