Working With Forms > The Form Objects > Check Box

Check Box
The Check Box () form object represents a check box, which can be selected or cleared. A selected check box sets the data source value to on, and a cleared check box sets the value to off.
Enter the name of the Check Box object in the Name field.
Enter the label next to the check box in the Text field.
In addition, the Settings window contains the following sections:
Source
In this section you specify the data source for the check box. The section contains a tree with a filtered view of the tree in the Application Builder window. The nodes either represent some sort of data or have children that do. For a check box, variables in the COMSOL model and scalar strings and Boolean variables that you define under Declarations are available as the data source. You can extend the list of available data nodes by clicking the Switch to Model Builder and Activate Model Data Access button () in the Source section header, which takes you to the Model Builder, and then selecting a node in the Model Builder branch whose data you want to access. With this button active, the Settings window of the selected node displays a Select Data Source check box (a green square) next to the settings that you can include. Click to select the check box to include that data as an available source node for check boxes.
When you select a node that represents data, the Use as Source toolbar button () below the tree becomes enabled. You can right-click the node and choose Use as Source. You can also click the Create button () in the Source section header to create a new variable declaration and use it as the source. A Create and Use Variable dialog box opens, so that you can select the data type of the source (if applicable), its name, and its initial value. The name cannot be in conflict with any existing variable declaration. Click the Edit Node toolbar button () below the tree to move to the corresponding node. If necessary, the program switches to the Model Builder.
After selecting a node as the source, the node appears as the selected source under Selected source.
From the Initial value list, select From data source to link this check box to a variable defined in the Source section above and use the value specified by that data source. Select Custom value to specify the initial state from the Initial state list: Selected (the default) or Cleared. The value for a selected check box is on, and for a cleared check box it is off.
If a global parameter is the data source of the check box, it is necessary to add two parameters, on and off, with values 1 and 0, respectively. Otherwise, you get an error when the COMSOL software looks for the parameters on and off.
Position and Size
This section contains all layout settings for a check box in the grid of the parent form.
In the grid mode, you can control the horizontal and vertical alignment of the check box using the following lists:
From the Horizontal alignment list, choose Left, Center, Right, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
From the Vertical alignment list, choose Middle, Top, Bottom, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
The need to specify the alignment is most obvious when working in the grid mode; then it controls how the form object is aligned in its grid cell. Aligning the form object can be useful in the sketch mode too, and you can then use the alignment tools on the Arrange menu in the Form toolbar’s Sketch section. When running the application in any client other than the Windows client, the form objects may not be positioned exactly as seen in the Application Builder. This is because the form objects may have a different size in other clients, giving them a slightly different positioning. Specifying the alignment ensures that the form objects are aligned as you want them to be in all clients.
The Width and Height fields are unavailable because the dimensions of the check box are determined by the software.
Additionally, in the sketch mode, you can specify the form object’s absolute position using the Position x and Position y fields. In the grid mode, you can position the object in the grid and see the grid position as the Row, Column, Row span, and Column span values.
Cell Margin
Under Cell margin (in grid mode only), you can control the margins around the form object. By default, the margins are taken from the parent form. From the Cell margin list, choose:
None, to use no margin around the form object.
From parent form (the default), to use the margins set for the parent form.
Custom, to specify the margins for the form object in the Horizontal and Vertical text fields.
Appearance
In this section, you can control the appearance of the background and the text on the check box label:
From the Text color list, select a color to use for the text: Inherit (the default; the form object then uses the setting from the Form it is located in), any of the predefined basic colors, or Custom, which makes it possible to select a custom color from a color palette that opens.
From the Background color list, select a color to use as the background in the check box: Transparent (the default), any of the predefined basic colors, or Custom, which makes it possible to select a custom color from a color palette that opens.
The font and the font size for the button label use the font settings from the Forms node by default. Select a font from the Font list: Default font or any of the available fonts. If needed, choose or enter a font size (in points) in the Font size combo box. The default is to use the Default size for the font.
Select the Bold check box to use a boldface font.
Select the Italic check box to use italics (an italic font).
Select the Underline check box to underline the text.
Under State, you can control the initial state of the check box when users run the application. By default, the check box is visible and enabled. Clear the Visible or Enabled check box if you want to make the initial state so that the check box is hidden or unavailable. You can then make it visible or enable it using a method.
Events
You can add a code method that the application runs when the user changes the value of the check box. The event is triggered after the new data value is stored in the data source. The On data change list contains None (the default) and any available methods. To add a local method for this event, click the Create Local Method button () or right-click the check box object. The selected method in the On data change list then changes to Local method. To open the local method, click the Go to Source button (). An empty onDataChange editor window then opens, where you can define the local method. Click the Remove Local Method button () to delete the local method.
You can also Ctrl+Alt-click on the check box:
If the On data change list is set to a method, Ctrl+Alt-click opens that method’s editor window.
If the On data change list is set to None, Ctrl+Alt-click creates a local method if needed, sets the list to Local method, and opens the local method’s editor window.