C#WinForm的空白打印页面

时间:2017-08-30 09:30:40

标签: c# winforms printing

谨慎地将ToolboxForm1.cs[Design]拖放到void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { } void button1_Click(object sender, EventArgs e) { CaptureScreen(); printDocument1.Print(); printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); } Bitmap memoryImage; private void CaptureScreen() { Graphics myGraphics = this.CreateGraphics(); Size s = this.Size; memoryImage = new Bitmap(s.Width, s.Height, myGraphics); Graphics memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s); } void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(memoryImage, 0, 0); } ,然后运行以下代码:

.pdf

保存为CaptureScreen() method的打印页面为空。因此,虽然代码中没有错误,但def maybe_float(s): try: return float(s) except (ValueError, TypeError): return s orig_list = ['data', '18', '17', '0'] the_list = [maybe_float(v) for v in orig_list] 似乎无法以某种方式工作。对于任何反馈,我们都表示感谢。最好

1 个答案:

答案 0 :(得分:0)

要绘制控件的客户区,您可以使用以下代码段:

private Bitmap DrawToBitmap()
{
  using(Graphics g = this.CreateGraphics())
  {
    var bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height, g);
    using(Graphics gBmp = Graphics.FromImage(bmp))
    {
      PaintEventArgs e = new PaintEventArgs(gBmp, this.ClientRectangle);
      this.OnPaint(e);        
    }        
  }
}