CheckBox.CheckAlign 属性
获取或设置 CheckBox 控件上的复选框的水平和垂直对齐方式。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<BindableAttribute(True)> _
<LocalizableAttribute(True)> _
Public Property CheckAlign As ContentAlignment
用法
Dim instance As CheckBox
Dim value As ContentAlignment
value = instance.CheckAlign
instance.CheckAlign = value
[BindableAttribute(true)]
[LocalizableAttribute(true)]
public ContentAlignment CheckAlign { get; set; }
[BindableAttribute(true)]
[LocalizableAttribute(true)]
public:
property ContentAlignment CheckAlign {
ContentAlignment get ();
void set (ContentAlignment value);
}
/** @property */
public ContentAlignment get_CheckAlign ()
/** @property */
public void set_CheckAlign (ContentAlignment value)
public function get CheckAlign () : ContentAlignment
public function set CheckAlign (value : ContentAlignment)
属性值
ContentAlignment 值之一。默认值为 MiddleLeft。
异常
异常类型 | 条件 |
---|---|
所分配的值不是 ContentAlignment 枚举值之一。 |
示例
下面的代码示例将在一个标签中显示三个属性的值。连续单击该控件会使 ThreeState 属性交替设置为 true 和 false,而 CheckAlign 会交替设置为 ContentAlignment 的 MiddleRight 和 MiddleLeft 值。此示例显示属性值如何在更改 ThreeState 属性和选中该控件时发生更改。此示例要求 CheckBox、Label 和 Button 已全部在窗体上实例化,并且标签的大小足以显示三行文本和对 System.Drawing 命名空间的引用。应当在该控件的 Click 事件处理程序中调用此代码。
Private Sub AdjustMyCheckBoxProperties()
' 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()
' 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
End Sub 'AdjustMyCheckBoxProperties
private void AdjustMyCheckBoxProperties()
{
// Concatenate the property values together on three lines.
label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
"Checked: " + checkBox1.Checked.ToString() + "\n" +
"CheckState: " + checkBox1.CheckState.ToString();
// 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()
{
// 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()
{
// Concatenate the property values together on three lines.
label1.set_Text("ThreeState: " + checkBox1.get_ThreeState() + "\n"
+ "Checked: " + checkBox1.get_Checked() + "\n"
+ "CheckState: " + checkBox1.get_CheckState());
//Change the ThreeState and CheckAlign properties on every other click.
if (!(checkBox1.get_ThreeState())) {
checkBox1.set_ThreeState(true);
checkBox1.set_CheckAlign(ContentAlignment.MiddleRight);
}
else {
checkBox1.set_ThreeState(false);
checkBox1.set_CheckAlign(ContentAlignment.MiddleLeft);
}
} //AdjustMyCheckBoxProperties
private function AdjustMyCheckBoxProperties()
{
// Concatenate the property values together on three lines.
label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
"Checked: " + checkBox1.Checked.ToString() + "\n" +
"CheckState: " + checkBox1.CheckState.ToString();
// 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;
}
}
平台
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
请参见
参考
CheckBox 类
CheckBox 成员
System.Windows.Forms 命名空间
ButtonBase.TextAlign 属性
ContentAlignment