form上画了一些矩形和圆形。
请教如何打印?可以给我个例子吗?

解决方案 »

  1.   

    Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
    Image img = new Bitmap(R.Width, R.Height);
    Graphics G = Graphics.FromImage(img);
    G.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(R.Width, R.Height));。   
    IntPtr dc = G.GetHdc();   
    G.ReleaseHdc(dc);
    G.Dispose();
    img .Save("c:\\a.jpg");

    private void DrawLabel(Label l, Graphics g)
      {
      Rectangle r = GetControlRect(l);
      if (l.AutoSize)
      {
      r.Width = (int)g.MeasureString(l.Text, l.Font).Width;
      }  if (l.BorderStyle != BorderStyle.None)
      {
      g.DrawRectangle(_pen, r);
      }
      r.Width = (int)(r.Width * 1.1);
      r.Height = (int)(r.Height * 1.1);
      if (l.TextAlign == ContentAlignment.BottomRight || l.TextAlign == ContentAlignment.MiddleRight || l.TextAlign == ContentAlignment.TopRight)
      g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r, new StringFormat(StringFormatFlags.DirectionRightToLeft));
      else
      g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r);
      }