How to disable the parent form when a child form is active?

前端 未结 13 2133
闹比i
闹比i 2020-12-12 23:26

How to disable a parent form when child form is active using c#?

相关标签:
13条回答
  • 2020-12-13 00:05

    For me this work for example here what happen is the main menu will be disabled when you open the registration form.

     frmUserRegistration frmMainMenu = new frmUserRegistration();
        frmMainMenu.ShowDialog(this);
    
    0 讨论(0)
  • 2020-12-13 00:06

    Have you tried using Form.ShowDialog() instead of Form.Show()?

    ShowDialog shows your window as modal, which means you cannot interact with the parent form until it closes.

    0 讨论(0)
  • 2020-12-13 00:06

    Why not just have the parent wait for the child to close. This is more than you need.

    // Execute child process
    System.Diagnostics.Process proc = 
        System.Diagnostics.Process.Start("notepad.exe");
    proc.WaitForExit();
    
    0 讨论(0)
  • 2020-12-13 00:08

    Its simple, use

      Form.ShowDialog();
    

    Instead

      Form.Show();
    

    While using Form.ShowDialog()you cannot interact with the parent form until it closes.

    0 讨论(0)
  • 2020-12-13 00:10

    You can also use MDIParent-child form. Set the child form's parent as MDI Parent

    Eg

    child.MdiParent = parentForm;
    child.Show();
    

    In this case just 1 form will be shown and the child forms will come inside the parent. Hope this helps

    0 讨论(0)
  • 2020-12-13 00:11

    You can do that with the following:

    Form3 formshow = new Form3();
    
    formshow.ShowDialog();
    
    0 讨论(0)
提交回复
热议问题