为什么切换窗体的可见性会禁用KeyDown事件?

| 我正在运行时创建一个
Panels
的网格,由于它是由循环创建的,因此在调整大小时非常难看。为了“隐藏”此操作,我打电话给
this.Visible = false;
在我循环之前
this.Visible = true;
在我循环之后。
 for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                _panel = new Panel();
                _panel.Location = new Point((i * _panel.Size.Width) + ((i + 1) * _border), (j * _panel.Size.Height) + ((j + 1) * _border));                    
                this.Controls.Add(_panel);
            }
        }
上面的代码可以很好地工作,但是只能工作一次。 切换表单的可见性后,按键将不再发生
KeyDown
事件。 有任何想法吗?     
已邀请:
您永远不应更改更新操作的可见性。而是使用:
this.SuspendLayout();

// Do all the resizing here.

this.ResumeLayout();
    
this.Visible
是服务器端调用,可防止html控件和该控件的所有内容不呈现给客户端。您可以尝试将样式更改为
style=\"display:none;
,以便将\ panel \中的所有内容重新传输到客户端。     

要回复问题请先登录注册