C#中提示:创建窗口句柄时出错。解决方案 只是用于我这个情况

今天在打开程序的时候出现了 创建窗口句柄时出错。程序无法启动。经排查发现时

我在一个叫做Canvas的Form窗体上重载了一个消息函数 

  protected override void WndProc(ref Message m)
        {
           
            base.WndProc(ref m);
            if (m.Msg == WM_IME_SETCONTEXT && m.WParam.ToInt32() == 1)
            {
                ImmAssociateContext(this.Handle, m_hImc);
            }
            switch (m.Msg)
            {
                case WM_CHAR:
                    KeyEventArgs e = new KeyEventArgs(((Keys)((int)((long)m.WParam))) | ModifierKeys);
                    if (s.selEle is TextBox2)
                    {
                        TextBox2 textBox2 = (TextBox2)s.selEle;
                        sb.Remove(0, sb.Length);
                        sb.Append(textBox2.ParameterKey );
                    }
                    char a = (char)e.KeyData; 
                    if (e.KeyCode == Keys.Back)
                    {
                        if (sb.Length >= 1)
                        {
                            sb.Remove(sb.Length - 1, 1);
                           
                        }
                    }
                    else if (e.KeyCode == Keys.Enter)
                    {
                        sb.AppendLine();
                    }
                    else
                    {
                        sb.Append(a);
                    }
                    if (s.selEle is TextBox2)
                    {
                        TextBox2 textBox2 = (TextBox2)s.selEle;
                        textBox2.ParameterKey = sb.ToString();
                        textBox2.Text = sb.ToString();
                    }
                    this.Invalidate();
                    break;
                case 522:
                    this.VerticalScroll.Enabled = false;
                    this.HorizontalScroll.Enabled = false;
                    break;
            }
          
        }

忘记写base.WndProc(ref m); 这行代码照成。
将这行代码加上窗体正常启动

你可能感兴趣的:(C#中提示:创建窗口句柄时出错。解决方案 只是用于我这个情况)