You will use these two classes for the arrangement of components in a container or for the alignment of, for example, text in a text box or an image in a picture box.
This static class provides constants and 6 methods that are used to specify the alignment of objects or text, provided they have the Alignment property. The Draw.Text method also uses the constants of the Align class.
To specify the alignment of visible objects, knowledge of the direction matrix is as necessary as the associated constants for the designated directions:
Align | Constant | Symbol | Description |
---|---|---|---|
.BottomLeft | 33 | ↙ | Alignment horizontal left and vertical bottom |
.Bottom | 35 | ↓ | Alignment horizontally centred and vertically below |
.BottomRight | 34 | ↘ | Alignment horizontal right and vertical bottom |
.Left | 1 | ← | Alignment horizontal left and vertical centre |
.Center | 3 | ※ | Alignment horizontal and vertical centre |
.Right | 2 | → | Alignment horizontal right and vertical centre |
.TopLeft | 17 | ↖ | Alignment horizontal left and vertical top |
.Top | 19 | ↑ | Alignment horizontally centred and vertically on top |
.TopRight | 18 | ↗ | Alignment horizontal right and vertical top |
Table 20.7.1.1: Direction matrix - constants for the Alignment property.
If you use the alignment of text, for example, with the editor TextEdit to specify the alignment of text, note the dependence on the writing direction of the language used:
Align | Constant | Description |
---|---|---|
.Normal | 0 | Alignment vertically centred and horizontally according to the writing direction |
.TopNormal | 16 | Alignment vertically on top and horizontally according to the writing direction |
.BottomNormal | 32 | Alignment vertically bottom and horizontally according to the writing direction |
.Justify | 4 | Alignment horizontally and vertically centred |
Table 20.7.1.2.1: Alignment of text according to writing direction
All property values from the upper tables can be set or read out using the 6 methods IsBottom, IsCenter, IsLeft, IsMiddle, IsRight and IsTop, as shown in Example 1:
Public Sub btnSetCenter_Click() If Not Align.IsCenter(PictureBox1.Alignment) Then PictureBox1.Alignment = Align.Center Endif End
Example 2
This is how you set the text alignment of a text box - analogously also of a MaskBox - and a textarea:
... TextBox1.Text = "Ausrichtung" TextBox1.Alignment = Align.Right TextArea1.Alignment = Align.Normal ...
If, on the other hand, you want to align the current paragraph or the selected text in the TextEdit editor, set the property TextEdit.Format.Alignment with the 4 alignments Normal, Left, Center and Right :
Public Sub btnSetProperty_Click() TextEdit1.Format.Alignment = Align.Center TextEdit1.Format.Color = Color.Red TextEdit1.Format.Background = Color.LightGray TextEdit1.Format.Font = Font["FreeMono,14"] End
This class is static. It provides constants that can be used to set the Arrange property of many components if they have the Arrange property. Only components that act as containers for other components such as Shape, Panel, Expander, DrawingArea1 or TabStrip have the Arrangement property. The arrangement of components must always be specified relative to the container.
Arrange | Constant | Description |
---|---|---|
.None | 0 | Default value. The arrangement of the components in the client area of the container is not affected. |
.Horizontal | 1 | The components in the container are arranged next to each other and are given the height of the container. Their width is not affected. The component in the container whose value Component.X is the smallest is displayed on the left. If these values are the same, the position in the hierarchy decides. |
.Vertical | 2 | The components in the container are arranged below each other and receive the width of the container. Their height is not affected. The component in the container whose value Component.Y is the smallest is displayed at the top. If these values are the same, the position in the hierarchy decides. |
.Column | - | - |
.TopBottom | 4 | The components are stacked in a column in the container if the height is sufficient. Otherwise another column is created. |
.Row | - | - |
.LeftRight | 3 | The components are arranged in a row in the container, if the width is sufficient. Otherwise another row is created under the existing one. |
.Fill | 5 | One component in the container fills the entire client area in the container. Multiple components do not make sense. If there are nevertheless several components in the container, then the component that is in the last position in the hierarchy - in relation to the container - is displayed. |
Table 20.7.2.1: Constants for the Arrangement Property
You can use the values specified in Table 20.7.2.1 to arrange components in a container. When arranging components in a container, you can make further adjustments using the container properties Spacing and Padding:
Example 1
Three buttons are added to a Panel1. The following properties are set:
Figure 20.7.2.1.1: Design (Panel1 at design time).
Figure 20.7.2.1.2: Horizontal (Panel1. Arrangement = 1)
Figure 20.7.2.1.3: Row (Panel1. Arrangement = 3 (Row))
If you reduce another container with the three buttons instead of a panel - a window is very suitable - then you can easily see the effect of creating a new column. With the assignment Panel1. Arrangement = Arrange.Row you get the arrangement in Figure 20.7.1.3.
Example 2
An HSplit component is placed on the form FMain. With the instruction
FMain.Arrangement = Arrange.Fill
the HSplit component completely fills the space in the container form.
Chapter