3
votes

What I implement

  • My application hold mdi child forms(don't close) when user opens other child to keep last input data.
  • Child forms are shown as Maximized.

What I want to stop

  • When user input arrow keys after over two child forms were opened(I think it's when child form focused), child forms are navigated(Up/Left : prev child open, Down/Right : next child) and shown as Maximized property is released(some case didn't).

I have searched for long time, there are some solutions about capturing keys but any solutions for stop this.

Please help me.

+ conditions to reproduce this problem

  • MDI parent has ToolStripPanel & ToolStrip docking at the right
  • parent also have MenuStrip(Visible property set to false) docking at the top to hide child form's control box
  • ToolStripButton's Click Event Handler show child form using spaghetti function like next
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;
}
  1. Load MDIParent enter image description here
  2. Click each ToolStripButton and Load Child Form enter image description here
  3. Push 'Up' arrow key just one time enter image description here
1
Do you want to build this navigation or do you have it and want to stop it ?GuidoG
@GuidoG I have and want to stop itTony Jang
I dont have this in my mdi application. Can you describe what I need to do in my mdi application to reproduce the problemGuidoG
@GuidoG I upload pictures and sample code.Tony Jang
plz someone edit grammatical errorsTony Jang

1 Answers

1
votes

Add PreviewKeyDown event handler to your MDI Child form. It can filter keys you want your child form to handle.

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;
    }
}