title: how to print a screen capture in wpf
body: <p>first I don't speak English fluently.
  Anyway.
  I'm trying to do this.
  However it does not third day.
  I'm doing now is program screen print after screen capture.
  I refer to this code.
  <a href="https://social.msdn.microsoft.com/Forums/windows/en-US/0623964c-4bb4-44c0-a1cb-4dbb2fa161f0/need-simple-c-code-to-print-a-screen-capture?forum=winforms" rel="nofollow">https://social.msdn.microsoft.com/Forums/windows/en-US/0623964c-4bb4-44c0-a1cb-4dbb2fa161f0/need-simple-c-code-to-print-a-screen-capture?forum=winforms</a></p>
  
  <p>but this only for winform.
  I tried to be tried the same from wpf with that.
  I want to auto fit to page.
  Here is my code</p>
  
  <pre><code>    Bitmap bmpScreenshot;
      void bt1_MouseDown(object sender, MouseButtonEventArgs e)
      {
          var cv = sender as Canvas;
          var btName = cv.Name;
  
          if (btName.Contains("8"))
          {
              MakeScreenshot();
  
              PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
              System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
  
  
              pd.DefaultPageSettings.Landscape = true;
  
              pd.PrintPage += printPage;
  
              if (printDlg.ShowDialog() == true)
              {
                  pd.Print();
              }
          }
      }
  
  
  
  
      public System.Windows.Point Location
      {
          get
          {
              return new System.Windows.Point(Left, Top);
          }
          set
          {
              Left = value.X;
              Top = value.Y;
          }
      }
  
  
  
      public void MakeScreenshot()
      {             
          Graphics g = Graphics.FromHwnd(new System.Windows.Interop.WindowInteropHelper(this).Handle);
  
          FrameworkElement pnlClient = this.Content as FrameworkElement;
          double dWidth = -1;
          double dHeight = -1;
  
          if (pnlClient != null)
          {
              dWidth = pnlClient.ActualWidth;
              dHeight = pnlClient.ActualHeight;
          }
  
          var desktop = System.Windows.SystemParameters.WorkArea;
          this.Left = desktop.Right - this.Width;
          this.Top = desktop.Bottom - this.Height;
  
  
          bmpScreenshot = new Bitmap((int)dWidth, (int)dHeight, g);
          var memoryGrphics = Graphics.FromImage(bmpScreenshot);
          memoryGrphics.CopyFromScreen((int)this.Location.X, (int)this.Location.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size);
  
         }           
          bmpScreenshot.Save("Screenshot.png", System.Drawing.Imaging.ImageFormat.Png);
  
      }
  
      private void printPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
      {
          e.Graphics.DrawImage(bmpScreenshot, 0, 0);
      }
  </code></pre>