مشاركة عبر


كيفية القيام بما يلي: تعيين خيارات عناصر تحكم CheckBox Windows Forms

يُستخدم عنصر تحكم Windows FormsCheckBox لمنح المستخدمين خيارات صواب/خطأ أو نعم/لا. يعرض عنصر تحكم علامة فحص عندما يتم تحديده.

لتعيين خيارات عناصر تحكم CheckBox

  • التحقق من قيمة خاصية Checked لتحديد حالتها, ثم استخدام هذه القيمة لتعيين خَيار.

    في مثال عينة التعليمات البرمجية أدناه ، متى ما تم تشغيل عنصر تحكم CheckBox لحدث CheckedChanged, سيتم تعيين خاصية AllowDrop الخاصة بالنموذج إلى false في حالة تحديد خانة الاختيار. وهذا مفيد في الحالات حيث تريد تقييد تدخل المستخدم.

    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.get_CheckState() == CheckState.Checked  ) 
       {
          // If checked, do not allow items to be dragged onto the form. 
          this.set_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;
          }
       }
    

راجع أيضًا:

المهام

كيفية القيام بما يلي: الاستجابة إلى نقر مربع اختيار Windows Forms

المرجع

نظرة عامة عن عنصر التحكم Windows Forms) CheckBox)

CheckBox

موارد أخرى

عنصر تحكم Windows Forms) CheckBox)