Gets or sets the alignment of the text in the up-down control.
[Visual Basic] Public Property TextAlign As HorizontalAlignment [C#] public HorizontalAlignment TextAlign {get; set;} [C++] public: __property HorizontalAlignment get_TextAlign(); public: __property void set_TextAlign(HorizontalAlignment); [JScript] public function get TextAlign() : HorizontalAlignment; public function set TextAlign(HorizontalAlignment);
One of the HorizontalAlignment values. The default value is Left.
Exception Type | Condition |
---|---|
InvalidEnumArgumentException | The value assigned is not one of the HorizontalAlignment values. |
The following example uses the derived class, NumericUpDown and sets some of its properties derived from UpDownBase. This code assumes you have a NumericUpDown control, two ComboBox controls, and three CheckBox controls instantiated on a form. Label the ComboBox controls: BorderStyle and TextAlign. Label the CheckBox controls: InterceptArrowKeys, ReadOnly, and UpDownAlign- Left. The code will allow you to change the property values at run time and see how each affect the appearance and behavior of the up-down control. See the table below for the appropriate values to be added to the ComboBox controls.
BorderStyle | TextAlign |
---|---|
None | Left |
Fixed3D | Right |
FixedSingle | Center |
[Visual Basic]
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Set the TextAlign property. Select Case ComboBox2.Text Case "Right" NumericUpDown1.TextAlign = System.WinForms.HorizontalAlignment.Right Case "Left" NumericUpDown1.TextAlign = System.WinForms.HorizontalAlignment.Left Case "Center" NumericUpDown1.TextAlign = System.WinForms.HorizontalAlignment.Center End Select End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Set the BorderStyle property. Select Case ComboBox1.Text Case "Fixed3D" NumericUpDown1.BorderStyle = System.WinForms.BorderStyle.Fixed3D Case "None" NumericUpDown1.BorderStyle = System.WinForms.BorderStyle.None Case "FixedSingle" NumericUpDown1.BorderStyle = System.WinForms.BorderStyle.FixedSingle End Select End Sub Private Sub CheckBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Evaluate and toggle the UpDownAlign property. If NumericUpDown1.UpDownAlign = System.WinForms.LeftRightAlignment.Left Then NumericUpDown1.UpDownAlign = System.WinForms.LeftRightAlignment.Right Else NumericUpDown1.UpDownAlign = System.WinForms.LeftRightAlignment.Left End If End Sub Private Sub CheckBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Evaluate and toggle the InterceptArrowKeys property. If NumericUpDown1.InterceptArrowKeys = True Then NumericUpDown1.InterceptArrowKeys = False Else NumericUpDown1.InterceptArrowKeys = True End If End Sub Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Evaluate and toggle the ReadOnly property. If NumericUpDown1.ReadOnly = True Then NumericUpDown1.ReadOnly = False Else NumericUpDown1.ReadOnly = True End If End Sub
UpDownBase Class | UpDownBase Members | System.WinForms Namespace | UpDownAlign