Bagikan melalui


Form.ActiveForm Properti

Definisi

Mendapatkan formulir aktif saat ini untuk aplikasi ini.

public:
 static property System::Windows::Forms::Form ^ ActiveForm { System::Windows::Forms::Form ^ get(); };
public static System.Windows.Forms.Form ActiveForm { get; }
public static System.Windows.Forms.Form? ActiveForm { get; }
static member ActiveForm : System.Windows.Forms.Form
Public Shared ReadOnly Property ActiveForm As Form

Nilai Properti

Form yang mewakili formulir aktif saat ini, atau null jika tidak ada formulir aktif.

Contoh

Contoh berikut mendapatkan formulir aktif dan menonaktifkan semua kontrol pada formulir. Contoh menggunakan Controls kumpulan formulir untuk melakukan iterasi melalui setiap kontrol pada formulir dan menonaktifkan kontrol.

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.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 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

Keterangan

Anda dapat menggunakan metode ini untuk mendapatkan referensi ke formulir yang saat ini aktif untuk melakukan tindakan pada formulir atau kontrolnya.

Jika aplikasi Anda adalah aplikasi antarmuka beberapa dokumen (MDI), gunakan ActiveMdiChild properti untuk mendapatkan formulir anak MDI yang saat ini aktif.

Berlaku untuk

Lihat juga