Gets or sets the text displayed in the up-down control.
[Visual Basic] Overridable Public Property Text As String [C#] public string Text {override get; override set;} [C++] public: __property virtual String* get_Text(); public: __property virtual void set_Text(String*); [JScript] public function get Text() : String; public function set Text(String);
The string value displayed in the up-down control.
If the Text property is set while the UserEdit property is set to true, the UpdateEditText method will be called. If the Text property is set while the UserEdit property is set to false, ValidateEditText will be called.
The following example uses the derived class, NumericUpDown. This code assumes you have a NumericUpDown control and a Button instantiated on a form. On the System.WinForms.Control.Click of the button, the point size of text in the NumericUpDown control increases. This will prompt the control to adjust its PreferredHeight property so all of the text is visible in the control. As the user types in a new value in the NumericUpDown control, the text is converted to a numeric value from a string value and validated to be between the System.WinForms.UpDownBase.Minimum and System.WinForms.UpDownBase.Maximum values. If the value is not valid, the Select method will select the text so the user can enter new a new value.
[Visual Basic]
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) ' If the entered value is greater than Minimum or Maximum, ' select the text and open a message box. If CInt(NumericUpDown1.Text) > NumericUpDown1.Maximum Or _ CInt(NumericUpDown1.Text) < NumericUpDown1.Minimum Then NumericUpDown1.Select 0, Len(NumericUpDown1.Text) MsgBox "The value entered was not between the Minimum and Maximum allowable values." _ & vbCrLf & "Please re-enter.", , "Invalid Value" End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Dim varPrefHeight1 As Integer Dim varPrefHeight2 As Integer ' Capture the PreferredHeight in variables before and after ' the Font is changed, display the results in a message box. varPrefHeight1 = NumericUpDown1.PreferredHeight Set NumericUpDown1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, _ System.Drawing.FontSize.Points, System.Drawing.FontWeight.Bold, False, False, _ False, System.Drawing.CharacterSet.Default, 0) varPrefHeight2 = NumericUpDown1.PreferredHeight MsgBox "Before Font Change: " & varPrefHeight1 & "After Font Change: " _ & varPrefHeight2, , "Preferred Height" End Sub
UpDownBase Class | UpDownBase Members | System.WinForms Namespace | UserEdit | UpdateEditText | ValidateEditText