title: C# - Windows Forms - Try to print - nothing is drawn - print dialog
body: <p>Could you help me about C# 2010?</p>
  <p>I want to print something by Print Dialog in Windows Forms.
  But nothing is drawn in the paper in Open XPS Virtual Printer.
  I have made a form with a button and a richTextBox.
  I have used a sample code from a website and I changed that code a little.</p>
  <p>here is the pictures:</p>
  <p><a href="https://i.stack.imgur.com/isbzJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/isbzJ.png" alt="enter image description here" /></a></p>
  <p>here is the code:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace FT_Pnt_01
  {
      public partial class Form1 : Form
      {
  
  
  
          PrintDialog PrintDialog1;
  
  
          public Form1()
          {
              InitializeComponent();
          }
  
          // Declare the PrintDocument object.
  
          private System.Drawing.Printing.PrintDocument docToPrint =
  
              new System.Drawing.Printing.PrintDocument();
  
  
  
  
          // This method will set properties on the PrintDialog object and
          // then display the dialog.
  
          private void button_Print_01_Click(System.Object sender,
  
              System.EventArgs e)
          {
  
  
              // Allow the user to choose the page range he or she would
              // like to print.
  
  
              PrintDialog1.AllowSomePages = true;
  
              // Show the help button.
  
              PrintDialog1.ShowHelp = true;
  
  
              // Set the Document property to the PrintDocument for
              // which the PrintPage Event has been handled. To display the
              // dialog, either this property or the PrinterSettings property
              // must be set
  
  
              PrintDialog1.Document = docToPrint;
  
              DialogResult result = PrintDialog1.ShowDialog();
  
  
              // If the result is OK then print the document.
  
              if (result == DialogResult.OK)
              {
                  docToPrint.Print();
              }
  
  
          }
  
  
          // The PrintDialog will print the document
          // by handling the document's PrintPage event.
  
  
          private void document_PrintPage(object sender,
  
              System.Drawing.Printing.PrintPageEventArgs e)
          {
              // Insert code to render the page here.
              // This code will be called when the control is drawn.
              // The following code will render a simple
              // message on the printed document.
  
  
              string text = &quot;پرینت گرفتن متن در سی شارپ&quot;;
  
              System.Drawing.Font printFont = new System.Drawing.Font
  
                  (&quot;Arial&quot;, 35, System.Drawing.FontStyle.Regular);
  
  
  
              MessageBox.Show(&quot;e.ToString() = &quot; + e.ToString());
  
  
  
  
              // Draw the content.
  
  
              e.Graphics.Clear(Color.Blue);
  
  
              e.Graphics.DrawString(text, printFont,
  
                  System.Drawing.Brushes.Black, 10, 10);
  
  
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
  
              PrintDialog1 = new PrintDialog();
  
  
          }
  
      }
  }
  </code></pre>