PrimalForms 2011: Spotlight on the CheckBox control

The “Spotlight on Controls” series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.

Last time we took a look at the ComboBox control. This time we will look at the CheckBox control:

CheckBox Control [System.Windows.Forms.CheckBox]

Represents a Windows check box control.

Default Event: CheckedChanged

Why use the CheckBox control?

Use the CheckBox control to retrieve or display True / False values .

Important Properties:

Checked

Indicates whether the checkbox is in the checked state.

Values (Default: False):

True

 Checked

False

Unchecked

Set the Checked property in the editor:

$checkbox1.Checked = $true

 

CheckAlign

Determines the location of the checkbox inside the control.

Why use the CheckAlign property? 

Use the CheckAlign property when you want to change the location of the check box in respect to the control’s space.

Values (Default: MiddleLeft):

TopLeft
Content is vertically aligned at the top and horizontally aligned on the left.

TopLeft

TopCenter
Content is vertically aligned at the top and horizontally aligned at the center.

TopCenter

TopRight
Content is vertically aligned at the top and horizontally aligned on the right.

TopRight

MiddleLeft
Content is vertically aligned in the middle and horizontally aligned on the left.

MiddleLeft

MiddleCenter
Content is vertically aligned in the middle and horizontally aligned at the center.

MiddleCenter

MiddleRight
Content is vertically aligned in the middle and horizontally aligned on the right.

MiddleRight

BottomLeft
Content is vertically aligned at the bottom and horizontally aligned on the left.

BottomLeft

BottomCenter
Content is vertically aligned at the bottom and horizontally aligned at the center.

BottomCenter

BottomRight
Content is vertically aligned at the bottom and horizontally aligned on the right.

BottomRight

TextAlign

The alignment of the text that will be displayed on the control.

Values (Default: MiddleLeft):

Shares the same values as CheckAlign property.

 

Important Events:

CheckedChanged

Occurs whenever the Check property is changed.

Why use the CheckedChanged event?

Use the CheckedChanged event when you wish to respond to when a user changes the check box state by modifying the form controls or running a script . For example, you may wish to disable certain controls depending on the checkbox’s current value.

In this example,  the event script disables the input textboxes for UserName and Password when the “Use Alternate Credentials” checkbox is unchecked.

$checkboxUseAltCred_CheckedChanged={
    #Enable or Disable the TextBox controls
    $textboxUserName.Enabled = $checkboxUseAltCred.Checked
    $textboxPassword.Enabled = $checkboxUseAltCred.Checked
}

When the checkbox is unchecked, the textboxes are disabled:

OnCheckedChanged Unchecked

When the checkbox is checked, the textboxes are enabled:

OnCheckedChanged Checked

 

Next on Spotlight on Controls:

The RadioButton control.