窗体在属性IsMdiContainer为true时,是不能接受keydown事件的。

解决方案 »

  1.   

    MainForm.cs:
    public MainForm()
    {
    parentWindow = this;
    }
    private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    switch (e.KeyCode)
    {
    case System.Windows.Forms.Keys.F2:
    OpenFrmRent();
    break;
    case System.Windows.Forms.Keys.F3:
    OpenFrmRent();             break;
    default:
    break;
    }
    }
    private void OpenFrmRent()
    {
    FrmRent frm=new FrmRent(parentWindow);
    frm.Show();
    }FrmRent.cs:
    public FrmRent(MainForm parent)
    {
    //
    // Win 窗体设计器支持所必需
    //
    InitializeComponent();
    this.MdiParent = parent; //使该视图成为主窗口的 Mdi 子级
    }private void FrmRent_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    switch (e.KeyCode)
    {
    case System.Windows.Forms.Keys.F5:
    this.Dispose(true);
    break;
    }
    }
    protected override void Dispose( bool disposing )
    {
    ActiveParent();
    bool tmpBool=this.MdiParent.Focused;
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose(disposing );

    }上面就是代码
    第一次导入的时候,IsMdiContainer=true,但是它是可以接受焦点事件的,可是打开子窗体的时候就丢失了焦点,请问如何让它找回焦点呢?
      

  2.   

    第一次导入的时候,IsMdiContainer=true,但是它是可以接受keydown事件的,可是打开子窗体再关闭后,父窗体就丢失了焦点,请问如何让它找回焦点呢?
      

  3.   

    捕获按键:只要把父窗体的KeyPreview变为true即可。