• 创建窗口句柄时出错解决思路


    创建窗口句柄时出错
    未处理 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

  • 相关阅读:
    【C++】虚函数
    ZF-net
    bzoj1061【NOI2008】志愿者招募
    highcharts 绘制图标的JAVASCRIPT 类库 收藏
    C语言中的const,free使用方法具体解释
    Java Transaction Management
    从有序数组中查找某个值 low_bound
    [华为机试练习题]35.找零钱
    1.9算法入门之进制转换
    uboot移植rtc
  • 原文地址:https://www.cnblogs.com/qiyecao/p/3445223.html
Copyright © 2020-2023  润新知