未处理 System.InvalidCastException
Message=无法将类型为“WindowsFormsApplication1.Form2”的对象强制转换为类型“System.Windows.Forms.PictureBox”。
Source=WindowsFormsApplication1
StackTrace:
在 WindowsFormsApplication1.Form2.pictureBox1_MouseDown(Object sender, MouseEventArgs e) 位置 G:\333\WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs:行号 44
在 System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.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(IntPtr 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()
在 WindowsFormsApplication1.Program.Main() 位置 G:\333\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:行号 21
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
“WindowsFormsApplication1.Form2”的对象强制转换为类型“System.Windows.Forms.PictureBox”。
看你的代码,你出错的那行代码(用了as或者强制类型转换),有个变量是picturebox,你赋值给form2类型了