title: c# - Print the winform in high quality?
body: <p>This question may sound familiar but i have searched internet and couldn't find a solution to it.</p>
  
  <p>I know for printing we can use <strong>Crystal Report</strong> but i am discarding that idea because of it's certain disadvantages. Here are some of the disadvantages:-</p>
  
  <ul>
  <li>Needs installation on PC and if the <strong>Visual Studio</strong> version is 2017 then you have to download 200MB+ setup.</li>
  <li>If you have made certain objects like <strong><em>textobject</em></strong> and <strong><em>lines</em></strong> in one section and you have to add something in the middle of it then you have to manually set location of every object otherwise if you collectively select all the object and move it then their original location and the spacing between each object gets lost.</li>
  <li>Currently i am using <strong>VS2008</strong> and it has crystal report integrated in it which has a <strong>well know problem of sometime changing the text of every textobject</strong> and adding an <strong>"i"</strong> in it for some reason.</li>
  </ul>
  
  <p>I also tried to download an <a href="https://netix.dl.sourceforge.net/project/reportingcloud/ReportingCloudBinaries.zip" rel="nofollow noreferrer">alternate to crystal report</a>. But its interface is not that friendly.</p>
  
  <h2>Alternate that i am choosing</h2>
  
  <p>Now i have designed my report on Windows Form. When i am trying to print, its quality is worse as compared to <strong>Crystal Reports</strong> print. Here is the code for it</p>
  
  <pre><code>    private System.IO.Stream streamToPrint;
      string streamType;
  
      private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
      {
          System.Drawing.Image image = System.Drawing.Image.FromStream(this.streamToPrint);
          int x = e.MarginBounds.X;
          int y = e.MarginBounds.Y;
          int width = image.Width;
          int height = image.Height;
          if ((width / e.MarginBounds.Width) &gt; (height / e.MarginBounds.Height))
          {
              width = e.MarginBounds.Width;
              height = image.Height * e.MarginBounds.Width / image.Width;
          }
          else
          {
              height = e.MarginBounds.Height;
              width = image.Width * e.MarginBounds.Height / image.Height;
          }
          System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
          e.Graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
      }
  
      private void btnPrint_Click(object sender, EventArgs e)
      {
          string fileName = Application.StartupPath + "\\PrintPage.jpg";
          using (Graphics gfx = this.CreateGraphics())
          {
              using (Bitmap bmp = new Bitmap(this.Width, this.Height, gfx))
              {
                  this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));
                  bmp.Save(fileName);
              }
          }
          FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
          StartPrint(fileStream, "Image");
          fileStream.Close();
          if (System.IO.File.Exists(fileName))
          {
              System.IO.File.Delete(fileName);
          }
      }
  
      public void StartPrint(Stream streamToPrint, string streamType)
      {
          this.printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
          this.streamToPrint = streamToPrint;
          this.streamType = streamType;
          System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
          PrintDialog1.AllowSomePages = true;
          PrintDialog1.ShowHelp = true;
          PrintDialog1.Document = printDoc;
          DialogResult result = PrintDialog1.ShowDialog();
          if (result == DialogResult.OK)
          {
              printDoc.Print();
              //docToPrint.Print();
          }
      }
  
      private void Frm_Test_Shown(object sender, EventArgs e)
      {
          try
          {
              btnPrint_Click(sender, e);
          }
          catch (Exception ex) { clsUtility.ShowErrMsg(ex.Message); }
      }
  </code></pre>
  
  <p>I understand the reason why it is doing so because of the image and screen resolution thing (Ref : <a href="https://stackoverflow.com/a/12547806/2994869">https://stackoverflow.com/a/12547806/2994869</a>). The workaround people mentioned was to increase the size of windows form and it's object by 6 times but that had the same result still the quality is worse.</p>
  
  <p>Is there any workaround or any trick that i can do to print a windows form so that quality is near to that of Crystal Report's.</p>