---
title: "print and preview page in C#"  
description: "print and preview page in C#"  
author: "Dematagoda kamal"  
published: 2013-02-12  
updated: 2013-02-12  
canonical: https://www.mindstick.com/forum/587/print-and-preview-page-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# print and preview page in C#

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!

I want to print [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) of richtextbox [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) in c#\
My line of code as below

Associate control to Print [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool)\
\
[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) void printDocument1_PrintPage(object sender, System.Drawing.[Printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy).PrintPageEventArgs e)\
{\
e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);\
e.Graphics.PageUnit = GraphicsUnit.Inch; \
}\
\
write code for printing and print [preview](https://www.mindstick.com/forum/429/i-want-to-get-full-path-of-lt-asp-fileupload-gt-and-then-client-can-click-the-preview-button-to-see-what-file-he-here-has-uploaded)\
\
private void btnPrint_Click(object sender, EventArgs e)\
{\
//PrintDialog associate with PrintDocument;\
printDialog1.Document = printDocument1;\
\
if (printDialog1.ShowDialog()==DialogResult.OK)\
{\
printDocument1.Print();\
}\
}\
\
private void btnPrintPreview_Click(object sender, EventArgs e)\
{\
//Associate PrintPreviewDialog with PrintDocument.\
printPreviewDialog1.Document = printDocument1; \
\
// Show PrintPreview [Dialog](https://www.mindstick.com/forum/562/jquery-dialog-box-not-closed-in-asp-dot-net-mvc-4)\
printPreviewDialog1.ShowDialog();\
}

[problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is when we have more text than its fits in [one page](https://www.mindstick.com/forum/118/problem-in-display-content-of-one-page-to-another-page)....... then we have to print it in next page.... I think I have to use e.HasMorePages = True to move to

next page.......... but its not working. its only prints first page until text fits in first page..

Thanks

## Replies

### Reply by AVADHESH PATEL

Hi Dematagoda!\
You have used e.HasMorePages=true. Its working but problem is that you have to put it in loop because at the end of first page it becomes false. \
Here I will give an algorithm which might be solve your problem. \

```
private void print_doc(......){      TextDocument doc = (TextDocument)sender;      //Some code is written here.      .      .      float x = e.MarginBounds.Left;   //set left margin.      float y = e.MarginBounds.Top;   //set right margin.        doc.PageNumber += 1;   //increasing page number by one.               if (doc.Offset < doc.Text.GetUpperBound(0))           {            e.HasMorePages = true;        } else {            doc.Offset = 0;        }}
```


---

Original Source: https://www.mindstick.com/forum/587/print-and-preview-page-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
