static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SpaceInvaders());// i get an error here when i start the form application.. it says Argument Exception. Parameter is not valid
}
我的主要表格如下所示:
public SpaceInvaders()
{
InitializeComponent();
}
public void SpaceInvaders_Load(object sender, EventArgs e)
{
}
这是堆栈跟踪
" 在 System.Drawing.Graphics.GetHdc()\r\n 在 System.Drawing.BufferedGraphics.RenderInternal(HandleRef refTargetDC, BufferedGraphics 缓冲区)\r\n 在 System.Drawing.BufferedGraphics.Render()\r\n 在 System .Windows.Forms.Control.WmPaint(Message& m)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r \n 在 System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n 在 System.Windows.Forms.Form.WndProc(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam )\r\n 在 System.Windows.Forms.UnsafeNativeMethods。DispatchMessageW(MSG& msg)\r\n 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n 在 System.Windows。 Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文)\r\n 在 System.Windows.Forms.Application。在 D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\SpaceInvaders\SpaceInvaders\Program.cs:line 18 中的 WindowsFormsApplication1.Program.Main() 处运行(Form mainForm)\r\n\r\n在 System.AppDomain._nExecuteAssembly(Assembly 程序集,String[] args)\r\n 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String[] args)\r\n 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)\r\n 在 System.Threading.ExecutionContext.Run( ExecutionContext executionContext、ContextCallback 回调、对象状态)\r\n 在 System.Threading.ThreadHelper.ThreadStart()"
“参数无效。”
我想我发现了问题:
public void Draw(Graphics g,int animationCell)
{
// some code
g.dispose()//that method threw the exception can someone tell me why? i thought you do need to dispose your graphics object at the end when you finish using it.
}