zoukankan      html  css  js  c++  java
  • 创建窗口句柄时出错解决思路

    创建窗口句柄时出错
    未处理 System.OutOfMemoryException
      Message="创建窗口句柄时出错。"
      Source="System.Windows.Forms"
      StackTrace:
      在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
      在 System.Windows.Forms.Control.CreateHandle()
      在 System.Windows.Forms.Form.CreateHandle()
      在 System.Windows.Forms.Control.get_Handle()
      在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
      在 System.Windows.Forms.Control.Show()
      在 ShengTeng.HIS.View.NSDoctorsAdvice.DoctorsAdviceForm.HomePToolStripButton_Click(Object sender, EventArgs e)行号 740
      在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
      在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
      在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
      在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      在 System.Windows.Forms.Control.WndProc(Message& m)
      在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
      在 System.Windows.Forms.ToolStrip.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)
      在 ShengTeng.HIS.STHIS.Program.Main() 位置Program.cs:行号 42
      在 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: System.NullReferenceException
      Message="未将对象引用设置到对象的实例。"
      Source="System.Windows.Forms"
      StackTrace:
      在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      在 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
      在 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
      在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
      InnerException:
    解决方案-属性-调试-把"启用非托管码调试"选上
    在看看
    ------解决方案--------------------
    这种问题,原因不好找的,尝试在Form的子类中重写一下CreateHandle,
    如果创建不成功,通过RecreateHandle,一般都会成功

    C# code
            protected override void CreateHandle()
            {
                if (!IsHandleCreated)
                {
                    try
                    {
                        base.CreateHandle();
                    } 
                    catch {}
                    finally
                    {
                        if (!IsHandleCreated)
                        {
                            base.RecreateHandle();
                        }
                    }
                }            
            } 

    摘录自http://www.myexception.cn/dotnet-framework/395508_2.html

  • 相关阅读:
    docker安装和hub
    sql获取时间、年龄
    在eclipse中配置Tomcat时,出现“Cannot create a server using the selected type”的错误。
    ajax简单做html查询删除(鲜花)
    java使用jsp建立项目+视频
    java根据数据库自动生成代码
    java连接数据库增删改查公共方法
    制作二维码java
    富文本编译器
    java字符串类型和时间类型的转换
  • 原文地址:https://www.cnblogs.com/qiyecao/p/3445223.html
Copyright © 2011-2022 走看看