如题:使用From.ShowDialog()方法显示模式窗口。在只有主窗口引用的情况下,通过什么途径可以获取到这个窗口的引用呢?
更进一步:怎么获取某个线程现在显示的所有窗口引用呢?例如:在单线程情况下,只知道主窗口的引用,怎么获取到所有现在显示的窗口引用呢?

解决方案 »

  1.   

    下面的代码示例获取活动窗体并禁用该窗体上的所有控件。该示例使用窗体的 Controls 集合循环访问窗体上的每个控件并禁用这些控件。public void DisableActiveFormControls()
     {
        // Create an instance of a form and assign it the currently active form.
        Form currentForm = Form.ActiveForm;
        
        // Loop through all the controls on the active form.
        for (int i = 0; i < currentForm.Controls.Count; i++)
        {
           // Disable each control in the active form's control collection.
           currentForm.Controls[i].Enabled = false;
        }
     }
      

  2.   

    谢谢了。我原来调试的时候Form.ActiveForm老是返回null,现在想想应该是调试的时候,进程中的窗口都被VS盖掉了~