Aracılığıyla paylaş


Windows Forms Onay Kutusu Tıklamalarına Nasıl Yanıt Verilir

Bir kullanıcı bir Windows Forms CheckBox denetimine tıklasa, Click olayı gerçekleşir. Uygulamanızı, onay kutusunun durumuna bağlı olarak bazı eylemler gerçekleştirecek şekilde programlayabilirsiniz.

CheckBox tıklamalarına yanıt vermek için

  1. Click olay işleyicisinde, denetimin durumunu belirlemek ve gerekli eylemleri gerçekleştirmek için Checked özelliğini kullanın.

    Private Sub CheckBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
       ' The CheckBox control's Text property is changed each time the
       ' control is clicked, indicating a checked or unchecked state.
       If CheckBox1.Checked = True Then
          CheckBox1.Text = "Checked"
       Else
          CheckBox1.Text = "Unchecked"
       End If
    End Sub
    
    private void checkBox1_Click(object sender, System.EventArgs e)
    {
       // The CheckBox control's Text property is changed each time the
       // control is clicked, indicating a checked or unchecked state.
       if (checkBox1.Checked)
       {
          checkBox1.Text = "Checked";
       }
       else
       {
          checkBox1.Text = "Unchecked";
       }
    }
    
    private:
       void checkBox1_CheckedChanged(System::Object ^ sender,
          System::EventArgs ^ e)
       {
          if (checkBox1->Checked)
          {
             checkBox1->Text = "Checked";
          }
          else
          {
             checkBox1->Text = "Unchecked";
          }
       }
    

    Uyarı

    Kullanıcı CheckBox denetimine çift tıklamayı denerse, her tıklama ayrı işlenir; diğer bir ifadeyle, CheckBox denetimi çift tıklama olayını desteklemez.

    Uyarı

    AutoCheck özelliği true olduğunda (varsayılan), tıklandığında CheckBox otomatik olarak seçilir veya temizlenir. Aksi takdirde, Checked olayı gerçekleştiğinde Click özelliğini el ile ayarlamanız gerekir.

    Eylem seyrini belirlemek için CheckBox denetimini de kullanabilirsiniz.

Onay kutusuna tıklandığında eylem seyrini belirlemek için

  1. Eylem seyrini belirlemek üzere CheckState özelliğinin değerini sorgulamak için bir case deyimi kullanın. ThreeState özelliği trueolarak ayarlandığında, CheckState özelliği işaretlenen kutuyu, işaretlenmemiş kutuyu veya seçeneğin kullanılamadığını belirtmek için kutunun soluk bir görünümle görüntülendiği üçüncü bir belirsiz durumu temsil eden üç olası değer döndürebilir.

    Private Sub CheckBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
       Select Case CheckBox1.CheckState
          Case CheckState.Checked
             ' Code for checked state.
          Case CheckState.Unchecked
             ' Code for unchecked state.
          Case CheckState.Indeterminate
             ' Code for indeterminate state.
       End Select
    End Sub
    
    private void checkBox1_Click(object sender, System.EventArgs e)
    {
       switch(checkBox1.CheckState)
       {
          case CheckState.Checked:
             // Code for checked state.
             break;
          case CheckState.Unchecked:
             // Code for unchecked state.
             break;
          case CheckState.Indeterminate:
             // Code for indeterminate state.
             break;
       }
    }
    
    private:
       void checkBox1_CheckedChanged(System::Object ^ sender,
          System::EventArgs ^ e)
       {
          switch(checkBox1->CheckState) {
             case CheckState::Checked:
                // Code for checked state.
                break;
             case CheckState::Unchecked:
                // Code for unchecked state.
                break;
             case CheckState::Indeterminate:
                // Code for indeterminate state.
                break;
          }
       }
    

    Uyarı

    ThreeState özelliği trueolarak ayarlandığında, Checked özelliği hem true hem de Checkediçin Indeterminate döndürür.

Ayrıca bakınız