我实施的内容
我想停止
我已经搜索了很长时间,有一些关于捕获键的解决方案,但有任何解决方案可以阻止它。
请帮帮我。
+重现此问题的条件
private void tsbChildForm1_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
if (m_frmChild != null)
{
if (typeof(Form1) != this.ActiveMdiChild.GetType())
{
m_frmChild = new Form1();
OpenChildForm(m_frmChild);
}
else
{
// do nothing. prevent memory increase
}
}
else
{
m_frmChild = new Form1();
OpenChildForm(m_frmChild);
}
}
private void OpenChildForm(Form frmChild)
{
if (LoadExistForm(frmChild))
{
// do nothing.
}
else
{
frmChild.MdiParent = this;
frmChild.WindowState = FormWindowState.Maximized;
frmChild.Show();
}
}
private bool LoadExistForm(Form frmChild)
{
foreach (Form frmEach in this.MdiChildren)
{
if (frmEach.Name.Equals(frmChild.Name, StringComparison.OrdinalIgnoreCase))
{
frmEach.Select();
frmEach.WindowState = FormWindowState.Maximized;
frmChild.Dispose();
return true;
}
}
return false;
}
答案 0 :(得分:1)
将PreviewKeyDown
事件处理程序添加到您的MDI子窗体。它可以过滤您希望子表单处理的键。
private void Form_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
case Keys.Down:
case Keys.Left:
case Keys.Right:
e.IsInputKey = true;
break;
}
}