C#.NET print WYSIWYG text in multiple pages from multiple text boxes
-
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.
-
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.
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.
-
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.
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
-
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
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.
-
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.
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.
-
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.
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
-
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
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.