【发布时间】:2016-04-24 16:03:51
【问题描述】:
我正在将代码从 VB6 翻译成 VB .NET。
这是VB6代码:
retval = BitBlt(Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, jdc, 0, 0, SRCCOPY)
等效的 VB .NET 代码为:
Dim gr As Graphics = Picture1.CreateGraphics()
Dim hdc As IntPtr = gr.GetHdc()
g_variable3D.retval = BitBlt(hdc, 0, 0, Picture1.Width, Picture1.Height, g_variable3D.jdc,
0, 0, TernaryRasterOperations.SRCCOPY)
当我运行代码时,我收到一条错误消息:
Dim hdc As IntPtr = gr.GetHdc()
错误信息说:
System.Drawing.dll 中出现“System.ArgumentException”类型的未处理异常。附加信息:参数无效。
这是堆栈跟踪:
StackTrace:
at System.Drawing.Graphics.GetHdc()
at frm3D.vb:line 313
at frm3D.Picture1_MouseMove(Object sender, MouseEventArgs e) in frm3D.vb:line 1176
at System.Windows.Forms.Control.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at My.MyApplication.Main(String[] Args) in :line 81
InnerException:
我查看了各种网站和论坛,但找不到解决此问题的线索。
我该如何处理这个异常?这里哪个参数无效?
【问题讨论】:
标签: vb.net vb6 drawing vb6-migration gdi