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

Graphics.CopyFromScreen 未处理Win32Exception 操作成功完成
程序中只要用到CopyFromScreen就报错
 private void Form1_Paint(object sender, PaintEventArgs e)
  {
  e.Graphics.CopyFromScreen(this.Location,
  new Point(4, 4), new Size(10, 10));
  }

详细错误信息:
未处理 System.ComponentModel.Win32Exception
  Message="操作成功完成。"
  Source="System.Drawing"
  ErrorCode=-2147467259
  NativeErrorCode=0
  StackTrace:
  在 System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
  在 System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize)
  在 System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
  在 TestCapture.Form1.Form1_Paint(Object sender, PaintEventArgs e) 位置 D:\测试用例\ZCCapture\TestCapture\Form1.cs:行号 48
  在 System.Windows.Forms.Control.OnPaint(PaintEventArgs e)
  在 System.Windows.Forms.Form.OnPaint(PaintEventArgs e)
  在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
  在 System.Windows.Forms.Control.WmPaint(Message& m)
  在 System.Windows.Forms.Control.WndProc(Message& m)
  在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
  在 System.Windows.Forms.Form.WndProc(Message& m)
  在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.Run(Form mainForm)
  在 TestCapture.Program.Main() 位置 D:\测试用例\ZCCapture\TestCapture\Program.cs:行号 18
  在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
  在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


------解决方案--------------------
同样的代码我这里没有错误。。。

你把工程rebuild一下,重新试试
------解决方案--------------------
e.Graphics.CopyFromScreen(this.Location,
new Point(4, 4), new Size(10, 10));

是不是位置有点不对啊