Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C#.NET print WYSIWYG text in multiple pages from multiple text boxes

C#.NET print WYSIWYG text in multiple pages from multiple text boxes

Scheduled Pinned Locked Moved C#
csharpwinforms
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anil Veeraghattapu 4
    wrote on last edited by
    #1

    Hi, I am developing a windows application in that i have some number of rich text box user controls the text in that rich text box can be bold, italic, various fonts and various colours now i need to implement a Print() which prints the text from all the rich text boxes. the printed content should be WYSIWYG... i am able to print the content form a single rich text box to multiple pages but i need to modify that in such a way that it prints each page for each rich text box. please provide me any sample codes or any examples Thanks Anil Veeraghattapu.

    A 1 Reply Last reply
    0
    • A Anil Veeraghattapu 4

      Hi, I am developing a windows application in that i have some number of rich text box user controls the text in that rich text box can be bold, italic, various fonts and various colours now i need to implement a Print() which prints the text from all the rich text boxes. the printed content should be WYSIWYG... i am able to print the content form a single rich text box to multiple pages but i need to modify that in such a way that it prints each page for each rich text box. please provide me any sample codes or any examples Thanks Anil Veeraghattapu.

      A Offline
      A Offline
      Arindam Sinha
      wrote on last edited by
      #2

      Anil, Check this out for C#[^] and this one for VB[^]. Hope this would help you.

      Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.

      A 1 Reply Last reply
      0
      • A Arindam Sinha

        Anil, Check this out for C#[^] and this one for VB[^]. Hope this would help you.

        Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.

        A Offline
        A Offline
        Anil Veeraghattapu 4
        wrote on last edited by
        #3

        Hi, That code is to print the content from only one rich text box control but i need to print the content from multiple text boxes. each page should have the text from each rich text box control Thanks Anil Veeraghattapu

        A 1 Reply Last reply
        0
        • A Anil Veeraghattapu 4

          Hi, That code is to print the content from only one rich text box control but i need to print the content from multiple text boxes. each page should have the text from each rich text box control Thanks Anil Veeraghattapu

          A Offline
          A Offline
          Arindam Sinha
          wrote on last edited by
          #4

          Anil709 wrote:

          That code is to print the content from only one rich text box control

          This surprised me :^) I donot know if you have even tried to achieve this implementation[^] for multiple text boxes. I did it for two text boxes. I just had some custom code (which i did really in a hurry, it can be organised more better) for two controls FirstrichTextBox & SecondrichTextBox. Follow the instructions as mentioned in that link and modify the BeginPrint and PrintPage events -

          private int checkPrintFirstControl;
          private int checkPrintSecondControl;
          bool firstControlDone = false;
          private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
          {
          checkPrintFirstControl = 0;
          checkPrintSecondControl = 0;
          }

          private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
          {
          //Verify if your First control is printed or not
          if (!firstControlDone)
          {
          // Print the content of First RichTextBox. Store the last character printed.
          checkPrintFirstControl = FirstrichTextBox.Print(checkPrintFirstControl, FirstrichTextBox.TextLength, e);

                      // Check if you are done with printing the first RichTextBox
                      if (checkPrintFirstControl >= FirstrichTextBox.TextLength)
                          firstControlDone = true;
                      //Setting this because you have to print second control
                      e.HasMorePages = true;
                  }
                  else
                  {
                      checkPrintSecondControl = SecondrichTextBox.Print(checkPrintSecondControl, SecondrichTextBox.TextLength, e);
          
                      // Check for more pages for the first RichTextBox
                      if (checkPrintSecondControl < SecondrichTextBox.TextLength)
                          e.HasMorePages = true;
                      else
                      {
                          e.HasMorePages = false;
                          firstControlDone = false;
                      }
          
                  }
          
              }
          

          If you need the full sample then send me your email id.

          Regards,

          A 2 Replies Last reply
          0
          • A Arindam Sinha

            Anil709 wrote:

            That code is to print the content from only one rich text box control

            This surprised me :^) I donot know if you have even tried to achieve this implementation[^] for multiple text boxes. I did it for two text boxes. I just had some custom code (which i did really in a hurry, it can be organised more better) for two controls FirstrichTextBox & SecondrichTextBox. Follow the instructions as mentioned in that link and modify the BeginPrint and PrintPage events -

            private int checkPrintFirstControl;
            private int checkPrintSecondControl;
            bool firstControlDone = false;
            private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
            {
            checkPrintFirstControl = 0;
            checkPrintSecondControl = 0;
            }

            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
            //Verify if your First control is printed or not
            if (!firstControlDone)
            {
            // Print the content of First RichTextBox. Store the last character printed.
            checkPrintFirstControl = FirstrichTextBox.Print(checkPrintFirstControl, FirstrichTextBox.TextLength, e);

                        // Check if you are done with printing the first RichTextBox
                        if (checkPrintFirstControl >= FirstrichTextBox.TextLength)
                            firstControlDone = true;
                        //Setting this because you have to print second control
                        e.HasMorePages = true;
                    }
                    else
                    {
                        checkPrintSecondControl = SecondrichTextBox.Print(checkPrintSecondControl, SecondrichTextBox.TextLength, e);
            
                        // Check for more pages for the first RichTextBox
                        if (checkPrintSecondControl < SecondrichTextBox.TextLength)
                            e.HasMorePages = true;
                        else
                        {
                            e.HasMorePages = false;
                            firstControlDone = false;
                        }
            
                    }
            
                }
            

            If you need the full sample then send me your email id.

            Regards,

            A Offline
            A Offline
            Anil Veeraghattapu 4
            wrote on last edited by
            #5

            Hi, your code is really impressive. it appears it will solve my problem. can you please send me the sample to my mail id my mailID: anilveeraghattapu@gmail.com Thanks Anil Veeraghattapu.

            1 Reply Last reply
            0
            • A Arindam Sinha

              Anil709 wrote:

              That code is to print the content from only one rich text box control

              This surprised me :^) I donot know if you have even tried to achieve this implementation[^] for multiple text boxes. I did it for two text boxes. I just had some custom code (which i did really in a hurry, it can be organised more better) for two controls FirstrichTextBox & SecondrichTextBox. Follow the instructions as mentioned in that link and modify the BeginPrint and PrintPage events -

              private int checkPrintFirstControl;
              private int checkPrintSecondControl;
              bool firstControlDone = false;
              private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
              {
              checkPrintFirstControl = 0;
              checkPrintSecondControl = 0;
              }

              private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
              {
              //Verify if your First control is printed or not
              if (!firstControlDone)
              {
              // Print the content of First RichTextBox. Store the last character printed.
              checkPrintFirstControl = FirstrichTextBox.Print(checkPrintFirstControl, FirstrichTextBox.TextLength, e);

                          // Check if you are done with printing the first RichTextBox
                          if (checkPrintFirstControl >= FirstrichTextBox.TextLength)
                              firstControlDone = true;
                          //Setting this because you have to print second control
                          e.HasMorePages = true;
                      }
                      else
                      {
                          checkPrintSecondControl = SecondrichTextBox.Print(checkPrintSecondControl, SecondrichTextBox.TextLength, e);
              
                          // Check for more pages for the first RichTextBox
                          if (checkPrintSecondControl < SecondrichTextBox.TextLength)
                              e.HasMorePages = true;
                          else
                          {
                              e.HasMorePages = false;
                              firstControlDone = false;
                          }
              
                      }
              
                  }
              

              If you need the full sample then send me your email id.

              Regards,

              A Offline
              A Offline
              Anil Veeraghattapu 4
              wrote on last edited by
              #6

              Hi it seems your code is trying to print text from only one text box right?? it could print either first text box data or from second text box data but what i need is i have to print text from all the text boxes in page wise i think you understood my problem. consider ms word. if you click on print preview it will prints text from each page of the word document to a real page. i want to achieve similar kind of thing. Thanks Anil Veeraghattapu

              A 1 Reply Last reply
              0
              • A Anil Veeraghattapu 4

                Hi it seems your code is trying to print text from only one text box right?? it could print either first text box data or from second text box data but what i need is i have to print text from all the text boxes in page wise i think you understood my problem. consider ms word. if you click on print preview it will prints text from each page of the word document to a real page. i want to achieve similar kind of thing. Thanks Anil Veeraghattapu

                A Offline
                A Offline
                Arindam Sinha
                wrote on last edited by
                #7

                Anil709 wrote:

                it could print either first text box data or from second text box data

                No..what I tried is to print both textboxes content in a single print click. Though I have no printer installed, I checked in the Print preview (I guess that should be enough). There, the First text box's content is shown in 2/3 pages and in next pages 2nd content is shown. Anyway I have sent you the code in your email id. Note - I coded very fast just to verify if multiple Rich text boxes can be printed or not. It could be done in better way. :)

                Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this message using rating.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups