日期:2014-05-18  浏览次数:20879 次

如何保存当前窗体为图片?
有没有知道一些的???
  this.Focus();
  SendKeys.Send("%{PRTSC}");
  IDataObject ido = Clipboard.GetDataObject();
  try
  {
  Image img = (Image)ido.GetData(DataFormats.Bitmap);
  img.Save(@"d:\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  }
  catch (System.Exception e1)
  {
  MessageBox.Show(e1.Message.ToString());
  }

这个代码有时候会抛出异常,有没有更好的代码参考一下

------解决方案--------------------
没做过,帮顶了
------解决方案--------------------
mark
------解决方案--------------------
http://topic.csdn.net/u/20080806/10/d1873709-4f50-4cd0-834e-c58c1d7a0cc9.html
------解决方案--------------------
那天看到过,帮你找找看
------解决方案--------------------
到底是要保存当前窗体(Form)还是屏幕?

从你的code里看来,似乎是从剪贴板里弄得图片。

IDataObject ido = Clipboard.GetDataObject();

你没有判断ido是否为null

抛出的异常是NullReferenceException吗?
------解决方案--------------------
C# code

private void DrawMeToBitmap(Control Obj)
        {
            int w = 0, h = 0;
            foreach (Control var in Obj.Controls)
            {
                if (var.Right > w)
                    w = var.Right;
                if (var.Bottom > h)
                    h = var.Bottom;
            }
            w++;
            h++;
            Bitmap bmp = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(bmp);
            using (Brush backColorBrush = new SolidBrush(Obj.BackColor))
            {
                g.FillRectangle(backColorBrush, new Rectangle(0, te

------解决方案--------------------
mark