CheckedListBox.CheckOnClick 属性

获取或设置一个值,该值指示当选定项时是否应切换复选框。

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

语法

声明
Public Property CheckOnClick As Boolean
用法
Dim instance As CheckedListBox
Dim value As Boolean

value = instance.CheckOnClick

instance.CheckOnClick = value
public bool CheckOnClick { get; set; }
public:
property bool CheckOnClick {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_CheckOnClick ()

/** @property */
public void set_CheckOnClick (boolean value)
public function get CheckOnClick () : boolean

public function set CheckOnClick (value : boolean)

属性值

如果立即应用选中标记,则为 true;否则为 false。默认为 false

备注

CheckOnClick 指示是否只要一选择项即切换复选框。默认行为是在首次单击时更改选定内容,然后让用户再次单击以应用选中标记。但在某些情况下,您可能愿意一单击项就选中它。

示例

下面的代码示例演示如何通过设置 CheckOnClickSelectionModeThreeDCheckBoxes 属性来初始化 CheckedListBox 控件。示例使用控件来填充 CheckedListBox,并将 DisplayMember 设置为控件的 Control.Name 属性。

要运行该示例,请将以下代码粘贴到一个窗体(该窗体包含名为 CheckedListBox1 的 CheckedListBox)中,并从该窗体的构造函数或 Load 方法中调用 InitializeCheckListBox 方法。

// This method initializes CheckedListBox1 with a list of all 
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.

internal System.Windows.Forms.CheckedListBox CheckedListBox1;

private void InitializeCheckedListBox()
{
    this.CheckedListBox1 = new CheckedListBox();
    this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
    this.CheckedListBox1.CheckOnClick = true;
    this.CheckedListBox1.Name = "CheckedListBox1";
    this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
    this.CheckedListBox1.TabIndex = 1;
    this.CheckedListBox1.SelectionMode = SelectionMode.One;
    this.CheckedListBox1.ThreeDCheckBoxes = true;

    foreach ( Control aControl in this.Controls )
    {
        this.CheckedListBox1.Items.Add(aControl, false);
    }

    this.CheckedListBox1.DisplayMember = "Name";
    this.CheckedListBox1.Items.Add(CheckedListBox1);
    this.Controls.Add(this.CheckedListBox1);
}
   // This method initializes CheckedListBox1 with a list of all 
   // the controls on the form. It sets the selection mode
   // to single selection and allows selection with a single click.
   // It adds itself to the list before adding itself to the form.
internal:
   System::Windows::Forms::CheckedListBox^ CheckedListBox1;

private:
   void InitializeCheckedListBox()
   {
      this->CheckedListBox1 = gcnew CheckedListBox;
      this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
      this->CheckedListBox1->CheckOnClick = true;
      this->CheckedListBox1->Name = "CheckedListBox1";
      this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
      this->CheckedListBox1->TabIndex = 1;
      this->CheckedListBox1->SelectionMode = SelectionMode::One;
      this->CheckedListBox1->ThreeDCheckBoxes = true;
      System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ aControl = safe_cast<Control^>(myEnum->Current);
         this->CheckedListBox1->Items->Add( aControl, false );
      }

      this->CheckedListBox1->DisplayMember = "Name";
      this->CheckedListBox1->Items->Add( CheckedListBox1 );
      this->Controls->Add( this->CheckedListBox1 );
   }

平台

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

请参见

参考

CheckedListBox 类
CheckedListBox 成员
System.Windows.Forms 命名空间