CheckBox.CheckAlign 属性

定义

获取或设置 CheckBox 控件上的复选框的水平和垂直对齐方式。

public:
 property System::Drawing::ContentAlignment CheckAlign { System::Drawing::ContentAlignment get(); void set(System::Drawing::ContentAlignment value); };
[System.ComponentModel.Bindable(true)]
public System.Drawing.ContentAlignment CheckAlign { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CheckAlign : System.Drawing.ContentAlignment with get, set
Public Property CheckAlign As ContentAlignment

属性值

ContentAlignment 值之一。 默认值是 MiddleLeft

属性

例外

所分配的值不是 ContentAlignment 枚举值之一。

示例

下面的代码示例显示标签中三个属性的值。 属性ThreeState在 和 false 之间true交替单击控件CheckAlign,并在 和 MiddleLeftContentAlignment值之间MiddleRight交替。 此示例演示属性值如何随着 ThreeState 属性更改和控件的检查而更改。 此示例要求 CheckBoxLabelButton 都已在窗体上实例化,并且标签足够大,以显示三行文本,以及对 命名空间的 System.Drawing 引用。 应在 控件的 Click 事件处理程序中调用此代码。

private:
   void AdjustMyCheckBoxProperties()
   {
      // Concatenate the property values together on three lines.
      label1->Text = String::Format( "ThreeState: {0}\nChecked: {1}\nCheckState: {2}",
         checkBox1->ThreeState, checkBox1->Checked, checkBox1->CheckState );
      
      // Change the ThreeState and CheckAlign properties on every other click.
      if ( !checkBox1->ThreeState )
      {
         checkBox1->ThreeState = true;
         checkBox1->CheckAlign = ContentAlignment::MiddleRight;
      }
      else
      {
         checkBox1->ThreeState = false;
         checkBox1->CheckAlign = ContentAlignment::MiddleLeft;
      }
   }
private void AdjustMyCheckBoxProperties()
 {
    // Change the ThreeState and CheckAlign properties on every other click.
    if (!checkBox1.ThreeState)
    {
       checkBox1.ThreeState = true;
       checkBox1.CheckAlign = ContentAlignment.MiddleRight;
    }
    else
    {
       checkBox1.ThreeState = false;
       checkBox1.CheckAlign = ContentAlignment.MiddleLeft;
    }

    // Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
                  "Checked: " + checkBox1.Checked.ToString() + "\n" +
                  "CheckState: " + checkBox1.CheckState.ToString(); 
 }
Private Sub AdjustMyCheckBoxProperties()

    ' Change the ThreeState and CheckAlign properties on every other click.
    If Not checkBox1.ThreeState Then
        checkBox1.ThreeState = True
        checkBox1.CheckAlign = ContentAlignment.MiddleRight
    Else
        checkBox1.ThreeState = False
        checkBox1.CheckAlign = ContentAlignment.MiddleLeft
    End If

    ' Concatenate the property values together on three lines.
    label1.Text = "ThreeState: " & checkBox1.ThreeState.ToString() & ControlChars.Cr & _
        "Checked: " & checkBox1.Checked.ToString() & ControlChars.Cr & _
        "CheckState: " & checkBox1.CheckState.ToString()

End Sub

适用于

另请参阅