Form.ActiveForm 属性

获取此应用程序的当前活动窗体。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Shared ReadOnly Property ActiveForm As Form
用法
Dim value As Form

value = Form.ActiveForm
public static Form ActiveForm { get; }
public:
static property Form^ ActiveForm {
    Form^ get ();
}
/** @property */
public static Form get_ActiveForm ()
public static function get ActiveForm () : Form

属性值

Form,表示当前活动窗体,或者如果没有活动窗体,则为 空引用(在 Visual Basic 中为 Nothing)。

备注

可以使用此方法获得对当前活动窗体的引用,以在该窗体或其控件上执行操作。

如果应用程序是多文档界面 (MDI) 应用程序,请使用 ActiveMdiChild 属性获得当前活动的 MDI 子窗体。

示例

下面的代码示例获取活动窗体并禁用该窗体上的所有控件。该示例使用窗体的 Controls 集合循环访问窗体上的每个控件并禁用这些控件。

Public Sub DisableActiveFormControls()
    ' Create an instance of a form and assign it the currently active form.
    Dim currentForm As Form = Form.ActiveForm
    
    ' Loop through all the controls on the active form.
    Dim i As Integer
    For i = 0 To currentForm.Controls.Count - 1
        ' Disable each control in the active form's control collection.
        currentForm.Controls(i).Enabled = False
    Next i
End Sub 'DisableActiveFormControls
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;
    }
 }
    
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;

   }
}
public void DisableActiveFormControls()
{
    // Create an instance of a form and assign it the currently 
    // active form.
    Form currentForm = Form.get_ActiveForm();

    // Loop through all the controls on the active form.
    for (int i = 0; i < currentForm.get_Controls().get_Count(); i++) {
        // Disable each control in the active form's control collection.
        currentForm.get_Controls().get_Item(i).set_Enabled(false);
    }
} //DisableActiveFormControls

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
ActiveMdiChild