PrintPreview?

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

    #1

    PrintPreview?

    Hi,

    I am using .Net Framework 2.0 final, and i use .Net printing library to
    print a document. I use printPreview dialog to print the document but after
    preview was shown, when i press the "print" button, i cannot print the
    document although there is some words on the preview. So, is there a bug in
    the preview?

    Thanks...


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: PrintPreview?

    Adam,

    Without seeing your code, it's impossible to say. You might have a bug
    in your code.

    Can you post a complete example?

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Adam Right" <adam@right.com > wrote in message
    news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Hi,
    >
    > I am using .Net Framework 2.0 final, and i use .Net printing library to
    > print a document. I use printPreview dialog to print the document but
    > after preview was shown, when i press the "print" button, i cannot print
    > the document although there is some words on the preview. So, is there a
    > bug in the preview?
    >
    > Thanks...
    >[/color]


    Comment

    • Adam Right

      #3
      Re: PrintPreview?

      Hi,

      Hi,

      My code is on the below,

      m_PrintDocument = new PrintDocument( );
      m_PrintDocument .PrintPage += new PrintPageEventH andler(
      m_PrintDocument _PrintPage );
      PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log ( );
      printPreviewDia log1.Document = m_PrintDocument ;
      Form m_Temp = ( Form ) printPreviewDia log1;
      m_Temp.WindowSt ate = FormWindowState .Maximized;
      printPreviewDia log1.ShowDialog ( );

      void m_PrintDocument _PrintPage( object sender, PrintPageEventA rgs e )
      {
      Font printFont = new Font ( "Courier" , 10 , FontStyle.Regul ar );
      String myString = "Trying";
      e.Graphics.Draw String( myString, printFont, Brushes.Black, 0, 0, new
      StringFormat( ) );
      }

      The printPreview dialog does not print my document although there are words
      on the document.
      Thanks..
      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:%232MBAj7D GHA.2724@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Adam,
      >
      > Without seeing your code, it's impossible to say. You might have a bug
      > in your code.
      >
      > Can you post a complete example?
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Adam Right" <adam@right.com > wrote in message
      > news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..[color=green]
      >> Hi,
      >>
      >> I am using .Net Framework 2.0 final, and i use .Net printing library to
      >> print a document. I use printPreview dialog to print the document but
      >> after preview was shown, when i press the "print" button, i cannot print
      >> the document although there is some words on the preview. So, is there a
      >> bug in the preview?
      >>
      >> Thanks...
      >>[/color]
      >
      >[/color]


      Comment

      • Adam Right

        #4
        Re: PrintPreview?

        Hi,

        can you give your mail address. I want to send yo an attachment in which
        there is a screen shot about this problem....

        "Adam Right" <adam@right.com > wrote in message
        news:Ox5pct7DGH A.2040@TK2MSFTN GP14.phx.gbl...[color=blue]
        > Hi,
        >
        > Hi,
        >
        > My code is on the below,
        >
        > m_PrintDocument = new PrintDocument( );
        > m_PrintDocument .PrintPage += new PrintPageEventH andler(
        > m_PrintDocument _PrintPage );
        > PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log ( );
        > printPreviewDia log1.Document = m_PrintDocument ;
        > Form m_Temp = ( Form ) printPreviewDia log1;
        > m_Temp.WindowSt ate = FormWindowState .Maximized;
        > printPreviewDia log1.ShowDialog ( );
        >
        > void m_PrintDocument _PrintPage( object sender, PrintPageEventA rgs e )
        > {
        > Font printFont = new Font ( "Courier" , 10 , FontStyle.Regul ar );
        > String myString = "Trying";
        > e.Graphics.Draw String( myString, printFont, Brushes.Black, 0, 0, new
        > StringFormat( ) );
        > }
        >
        > The printPreview dialog does not print my document although there are
        > words on the document.
        > Thanks..
        > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
        > in message news:%232MBAj7D GHA.2724@TK2MSF TNGP12.phx.gbl. ..[color=green]
        >> Adam,
        >>
        >> Without seeing your code, it's impossible to say. You might have a
        >> bug in your code.
        >>
        >> Can you post a complete example?
        >>
        >> --
        >> - Nicholas Paldino [.NET/C# MVP]
        >> - mvp@spam.guard. caspershouse.co m
        >>
        >> "Adam Right" <adam@right.com > wrote in message
        >> news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
        >>> Hi,
        >>>
        >>> I am using .Net Framework 2.0 final, and i use .Net printing library to
        >>> print a document. I use printPreview dialog to print the document but
        >>> after preview was shown, when i press the "print" button, i cannot print
        >>> the document although there is some words on the preview. So, is there a
        >>> bug in the preview?
        >>>
        >>> Thanks...
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: PrintPreview?

          Adam,

          You can post it here, and I will see it. No need to hide it from the
          rest of the group.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Adam Right" <adam@right.com > wrote in message
          news:eySIW67DGH A.2704@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Hi,
          >
          > can you give your mail address. I want to send yo an attachment in which
          > there is a screen shot about this problem....
          >
          > "Adam Right" <adam@right.com > wrote in message
          > news:Ox5pct7DGH A.2040@TK2MSFTN GP14.phx.gbl...[color=green]
          >> Hi,
          >>
          >> Hi,
          >>
          >> My code is on the below,
          >>
          >> m_PrintDocument = new PrintDocument( );
          >> m_PrintDocument .PrintPage += new PrintPageEventH andler(
          >> m_PrintDocument _PrintPage );
          >> PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log ( );
          >> printPreviewDia log1.Document = m_PrintDocument ;
          >> Form m_Temp = ( Form ) printPreviewDia log1;
          >> m_Temp.WindowSt ate = FormWindowState .Maximized;
          >> printPreviewDia log1.ShowDialog ( );
          >>
          >> void m_PrintDocument _PrintPage( object sender, PrintPageEventA rgs e )
          >> {
          >> Font printFont = new Font ( "Courier" , 10 , FontStyle.Regul ar );
          >> String myString = "Trying";
          >> e.Graphics.Draw String( myString, printFont, Brushes.Black, 0, 0, new
          >> StringFormat( ) );
          >> }
          >>
          >> The printPreview dialog does not print my document although there are
          >> words on the document.
          >> Thanks..
          >> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
          >> in message news:%232MBAj7D GHA.2724@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
          >>> Adam,
          >>>
          >>> Without seeing your code, it's impossible to say. You might have a
          >>> bug in your code.
          >>>
          >>> Can you post a complete example?
          >>>
          >>> --
          >>> - Nicholas Paldino [.NET/C# MVP]
          >>> - mvp@spam.guard. caspershouse.co m
          >>>
          >>> "Adam Right" <adam@right.com > wrote in message
          >>> news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..
          >>>> Hi,
          >>>>
          >>>> I am using .Net Framework 2.0 final, and i use .Net printing library to
          >>>> print a document. I use printPreview dialog to print the document but
          >>>> after preview was shown, when i press the "print" button, i cannot
          >>>> print the document although there is some words on the preview. So, is
          >>>> there a bug in the preview?
          >>>>
          >>>> Thanks...
          >>>>
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Bruce Wood

            #6
            Re: PrintPreview?

            Nicholas,

            I prepared a response for Adam, telling him that he was using
            PrintDocument incorrectly. Then I read the "about PrintDocument"
            documentation for the .NET Framework 1.1, and found that he was
            following their instructions exactly. This let to a question:

            Do you know whether PrintPreviewDia log, when you choose "Print..." from
            the menu, re-uses the original instance of the PrintDocument you pass
            it, or instantiates a new PrintDocument for the printing process
            itself?

            I ask because I've always inherited from PrintDocument and overridden
            OnPrintPage, rather than handling the PrintPage event of a "vanilla"
            PrintDocument. The former approach has always worked for me. However,
            if PrintPreviewDia log instantiates a _new_ PrintDocument instance
            internally in order to print, the latter method (the method recommended
            by MS in its documentation) _won't_ work.

            Comment

            • Adam Right

              #7
              Re: PrintPreview?

              Hi,

              Is there a basic solution for this problem, i cannot understand complex
              english sorry...

              "Bruce Wood" <brucewood@cana da.com> wrote in message
              news:1136227963 .180319.131660@ o13g2000cwo.goo glegroups.com.. .[color=blue]
              > Nicholas,
              >
              > I prepared a response for Adam, telling him that he was using
              > PrintDocument incorrectly. Then I read the "about PrintDocument"
              > documentation for the .NET Framework 1.1, and found that he was
              > following their instructions exactly. This let to a question:
              >
              > Do you know whether PrintPreviewDia log, when you choose "Print..." from
              > the menu, re-uses the original instance of the PrintDocument you pass
              > it, or instantiates a new PrintDocument for the printing process
              > itself?
              >
              > I ask because I've always inherited from PrintDocument and overridden
              > OnPrintPage, rather than handling the PrintPage event of a "vanilla"
              > PrintDocument. The former approach has always worked for me. However,
              > if PrintPreviewDia log instantiates a _new_ PrintDocument instance
              > internally in order to print, the latter method (the method recommended
              > by MS in its documentation) _won't_ work.
              >[/color]


              Comment

              • Bruce Wood

                #8
                Re: PrintPreview?

                I have a potential solution, but it will have to wait until tomorrow,
                when I will be back in the office and will have a printer with which to
                test.

                I want to write a little test program to discover whether my theory is
                correct.

                Comment

                • Ron Allen

                  #9
                  Re: PrintPreview?

                  Adam,
                  Since you are putting the text at 0,0 on the page you may be outside the
                  'hard margin' of the printer and thus not printing anything. Try it again
                  with 100, 100 which should be 1" down and 1" right from the page edge using
                  the standard coordinates. Alternately you could try setting OriginAtMargins
                  to true for the PrintDocument (I think).

                  Ron Allen
                  "Adam Right" <adam@right.com > wrote in message
                  news:Ox5pct7DGH A.2040@TK2MSFTN GP14.phx.gbl...[color=blue]
                  > Hi,
                  >
                  > Hi,
                  >
                  > My code is on the below,
                  >
                  > m_PrintDocument = new PrintDocument( );
                  > m_PrintDocument .PrintPage += new PrintPageEventH andler(
                  > m_PrintDocument _PrintPage );
                  > PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log ( );
                  > printPreviewDia log1.Document = m_PrintDocument ;
                  > Form m_Temp = ( Form ) printPreviewDia log1;
                  > m_Temp.WindowSt ate = FormWindowState .Maximized;
                  > printPreviewDia log1.ShowDialog ( );
                  >
                  > void m_PrintDocument _PrintPage( object sender, PrintPageEventA rgs e )
                  > {
                  > Font printFont = new Font ( "Courier" , 10 , FontStyle.Regul ar );
                  > String myString = "Trying";
                  > e.Graphics.Draw String( myString, printFont, Brushes.Black, 0, 0, new
                  > StringFormat( ) );
                  > }
                  >
                  > The printPreview dialog does not print my document although there are
                  > words on the document.
                  > Thanks..
                  > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                  > in message news:%232MBAj7D GHA.2724@TK2MSF TNGP12.phx.gbl. ..[color=green]
                  >> Adam,
                  >>
                  >> Without seeing your code, it's impossible to say. You might have a
                  >> bug in your code.
                  >>
                  >> Can you post a complete example?
                  >>
                  >> --
                  >> - Nicholas Paldino [.NET/C# MVP]
                  >> - mvp@spam.guard. caspershouse.co m
                  >>
                  >> "Adam Right" <adam@right.com > wrote in message
                  >> news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
                  >>> Hi,
                  >>>
                  >>> I am using .Net Framework 2.0 final, and i use .Net printing library to
                  >>> print a document. I use printPreview dialog to print the document but
                  >>> after preview was shown, when i press the "print" button, i cannot print
                  >>> the document although there is some words on the preview. So, is there a
                  >>> bug in the preview?
                  >>>
                  >>> Thanks...
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Adam Right

                    #10
                    Re: PrintPreview?

                    Hi Ron,

                    I have tried that but the printed document still is empty. I do not
                    understand that if there are some words on the preview, what is the reason
                    that it does not print that words? in Beta 2, i can print with the same
                    code. So i am wondering about Framework 2.0 in which there may be a bug in
                    print document. I do not know how can i handle that problem, because it is
                    very important for me and my customers. Thanks...

                    "Ron Allen" <RonAllen@newsg roups.nospam> wrote in message
                    news:O$XC1SHEGH A.272@TK2MSFTNG P10.phx.gbl...[color=blue]
                    > Adam,
                    > Since you are putting the text at 0,0 on the page you may be outside
                    > the 'hard margin' of the printer and thus not printing anything. Try it
                    > again with 100, 100 which should be 1" down and 1" right from the page
                    > edge using the standard coordinates. Alternately you could try setting
                    > OriginAtMargins to true for the PrintDocument (I think).
                    >
                    > Ron Allen
                    > "Adam Right" <adam@right.com > wrote in message
                    > news:Ox5pct7DGH A.2040@TK2MSFTN GP14.phx.gbl...[color=green]
                    >> Hi,
                    >>
                    >> Hi,
                    >>
                    >> My code is on the below,
                    >>
                    >> m_PrintDocument = new PrintDocument( );
                    >> m_PrintDocument .PrintPage += new PrintPageEventH andler(
                    >> m_PrintDocument _PrintPage );
                    >> PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log ( );
                    >> printPreviewDia log1.Document = m_PrintDocument ;
                    >> Form m_Temp = ( Form ) printPreviewDia log1;
                    >> m_Temp.WindowSt ate = FormWindowState .Maximized;
                    >> printPreviewDia log1.ShowDialog ( );
                    >>
                    >> void m_PrintDocument _PrintPage( object sender, PrintPageEventA rgs e )
                    >> {
                    >> Font printFont = new Font ( "Courier" , 10 , FontStyle.Regul ar );
                    >> String myString = "Trying";
                    >> e.Graphics.Draw String( myString, printFont, Brushes.Black, 0, 0, new
                    >> StringFormat( ) );
                    >> }
                    >>
                    >> The printPreview dialog does not print my document although there are
                    >> words on the document.
                    >> Thanks..
                    >> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                    >> in message news:%232MBAj7D GHA.2724@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
                    >>> Adam,
                    >>>
                    >>> Without seeing your code, it's impossible to say. You might have a
                    >>> bug in your code.
                    >>>
                    >>> Can you post a complete example?
                    >>>
                    >>> --
                    >>> - Nicholas Paldino [.NET/C# MVP]
                    >>> - mvp@spam.guard. caspershouse.co m
                    >>>
                    >>> "Adam Right" <adam@right.com > wrote in message
                    >>> news:%23GWyVS5D GHA.3528@TK2MSF TNGP12.phx.gbl. ..
                    >>>> Hi,
                    >>>>
                    >>>> I am using .Net Framework 2.0 final, and i use .Net printing library to
                    >>>> print a document. I use printPreview dialog to print the document but
                    >>>> after preview was shown, when i press the "print" button, i cannot
                    >>>> print the document although there is some words on the preview. So, is
                    >>>> there a bug in the preview?
                    >>>>
                    >>>> Thanks...
                    >>>>
                    >>>
                    >>>[/color]
                    >>
                    >>[/color]
                    >
                    >[/color]


                    Comment

                    • Bruce Wood

                      #11
                      Re: PrintPreview?

                      I ran my little test using .NET 1.1, and I was wrong. Ron Allen's
                      solution is most likely the correct one.

                      In my case, your code, as written, works fine in print preview and when
                      printing from print preview. No problems at all in .NET 1.1.

                      I'm not using .NET 2.0, so I'll leave it to others to try to reproduce
                      this behaviour in 2.0.

                      Comment

                      • Ron Allen

                        #12
                        Re: PrintPreview?

                        OK, I had to try this here. The following works for me here using VS2005
                        both in preview mode and in printer output (although I haven't checked for
                        any hard margin offsets). Note that I've used a stock StringFormat object
                        and disposed of the Font created. I'm using a Lexmark Optra printer but I
                        don't think that the printer should make a difference. All my variable are
                        local as well.

                        Ron Allen
                        ----------------------------snippet---------------------------------------------------------
                        private void button1_Click(o bject sender, EventArgs e)
                        {
                        PrintDocument m_PrintDocument = new PrintDocument() ;
                        m_PrintDocument .PrintPage += new
                        PrintPageEventH andler(m_PrintD ocument_PrintPa ge);
                        PrintPreviewDia log printPreviewDia log1 = new PrintPreviewDia log();
                        printPreviewDia log1.Document = m_PrintDocument ;
                        printPreviewDia log1.WindowStat e = FormWindowState .Maximized;
                        printPreviewDia log1.ShowDialog ();
                        printPreviewDia log1.Dispose();
                        }

                        void m_PrintDocument _PrintPage(obje ct sender, PrintPageEventA rgs e)
                        {
                        Font printFont = new Font("Courier", 10, FontStyle.Regul ar);
                        String myString = "Trying";
                        e.Graphics.Draw String(myString , printFont, Brushes.Black, 100, 100,
                        StringFormat.Ge nericDefault);
                        printFont.Dispo se();
                        }

                        ----------------------------snippet---------------------------------------------------------
                        "Adam Right" <adam@right.com > wrote in message
                        news:ec9NKxIEGH A.2040@TK2MSFTN GP14.phx.gbl...[color=blue]
                        > Hi Ron,
                        >
                        > I have tried that but the printed document still is empty. I do not
                        > understand that if there are some words on the preview, what is the reason
                        > that it does not print that words? in Beta 2, i can print with the same
                        > code. So i am wondering about Framework 2.0 in which there may be a bug in
                        > print document. I do not know how can i handle that problem, because it is
                        > very important for me and my customers. Thanks...
                        >[/color]


                        Comment

                        Working...