How disable the main form when I have a sub-from open [closed]

浪尽此生 提交于 2019-12-14 04:15:15

问题


I've been looking everywhere and I haven't found the code to disable the main form when sub form is open(I could be just wording it wrong. Just like when you're opening a file if you try click on the application the Open flashes and makes a sound.

How do I make the application disable while I'm in the second form that isn't the main?

Edit: So this is where place it since everyone is asking

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
    {
        New_File newFile = new New_File();
        if (newFile.ShowDialog() == DialogResult.OK)
        {

        }
    }

Edit 2: Take 16 sec to open the file, and looks like:

Since you took all my rep I have to post a link http://puu.sh/aDBF4/9d7fd31926.png

I still don't understand why you guys are still downvoting me when I didn't what a ShowDialog was..


回答1:


If you want to show the sub-form while the main form is visible but in disable mode, just follow the code below:

subForm.ShowDialog(); //Shows both main and sub form , but the main form is not accessible .

But if you want to have your main form hidden, follow this example :

this.Hide(); //Hides the main form.
subForm.ShowDialog(); //Shows the sub form.
this.Show(); //Shows the main form again after closing the sub form.



回答2:


When you open the 'Sub Form' use

form1.ShowDialog();

This will show the new form and you won't be able to access anything outside it until that form is closed.




回答3:


You need to make the main form "own" the sub-form, and modally show the sub-form.

  • For WinForms: pass the owner to ShowDialog.
  • For WPF: Set the Owner then call ShowDialog.



回答4:


Winforms:

new Form2().ShowDialog();

Shows a Dialog. Nothing more to say.

A little neat trick:

int num = (int)new Form2().ShowDialog();

It's pretty simple, the MainForm won't be access-able until you hit a button in Form2.



来源:https://stackoverflow.com/questions/25109807/how-disable-the-main-form-when-i-have-a-sub-from-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!