创建窗口句柄时出错。(未处理 Win32Exception)

窗体在InitializeComponent的时候如果创建不成功,尝试在Form的子类中重写一下CreateHandle,如果创建不成功,通过RecreateHandle,一般都会成功的。如下:

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


 

你可能感兴趣的:(Win32,类,异常)