Bagikan melalui


Cara: Mengatur Opsi dengan Kontrol Kotak Centang Formulir Windows

Kontrol Formulir Windows CheckBox digunakan untuk memberi pengguna opsi True/False atau Ya/Tidak. Kontrol menampilkan tanda centang saat dipilih.

Untuk mengatur opsi dengan kontrol Kotak Centang

  1. Periksa nilai properti untuk menentukan statusnya, dan gunakan nilai tersebut Checked untuk mengatur opsi.

    Dalam sampel kode di bawah ini, saat CheckBox peristiwa kontrol CheckedChanged dinaikkan, properti formulir AllowDrop diatur ke false jika kotak centang dicentang. Ini berguna untuk situasi di mana Anda ingin membatasi interaksi pengguna.

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _  
       ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged  
       ' Determine the CheckState of the check box.  
       If CheckBox1.CheckState = CheckState.Checked Then  
          ' If checked, do not allow items to be dragged onto the form.  
          Me.AllowDrop = False  
       End If  
    End Sub  
    
    private void checkBox1_CheckedChanged(object sender, System.EventArgs e)  
    {  
       // Determine the CheckState of the check box.  
       if (checkBox1.CheckState == CheckState.Checked)
       {  
          // If checked, do not allow items to be dragged onto the form.  
          this.AllowDrop = false;  
       }  
    }  
    
    private:  
       void checkBox1_CheckedChanged(System::Object ^ sender,  
          System::EventArgs ^ e)  
       {  
          // Determine the CheckState of the check box.  
          if (checkBox1->CheckState == CheckState::Checked)
          {  
             // If checked, do not allow items to be dragged onto the form.  
             this->AllowDrop = false;  
          }  
       }  
    

Baca juga