UpDownBase.Text 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置数字显示框(也称为 up-down 控件)中显示的文本。
public:
virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public override string Text { get; set; }
member this.Text : string with get, set
Public Overrides Property Text As String
属性值
数字显示框中显示的字符串值。
示例
下面的代码示例使用派生类 NumericUpDown。 此代码要求 NumericUpDown 已在窗体上创建控件和 , Button 并且 System.Drawing 命名空间已添加为引用。 在 Click 按钮的 事件上,控件中 NumericUpDown 文本的点大小增加。 这会提示控件调整其 PreferredHeight 属性,以便在控件中显示所有文本。 用户输入新值并离开NumericUpDown控件后,文本将转换为字符串值中的数值,并验证是否介于 和 Maximum 值之间Minimum。 如果值无效, MessageBox 将显示 并显示错误,并且 Select 方法将选择文本,以便用户可以输入新值。
void numericUpDown1_Leave( Object^ /*sender*/, EventArgs^ /*e*/ )
{
/* If the entered value is greater than Minimum or Maximum,
select the text and open a message box. */
if ( (System::Convert::ToInt32( numericUpDown1->Text ) > numericUpDown1->Maximum) || (System::Convert::ToInt32( numericUpDown1->Text ) < numericUpDown1->Minimum) )
{
MessageBox::Show( "The value entered was not between the Minimum andMaximum allowable values.\nPlease re-enter." );
numericUpDown1->Focus();
numericUpDown1->Select(0,numericUpDown1->Text->Length);
}
}
void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
int varPrefHeight1;
/* Capture the PreferredHeight before and after the Font
is changed, and display the results in a message box. */
varPrefHeight1 = numericUpDown1->PreferredHeight;
numericUpDown1->Font = gcnew System::Drawing::Font( "Microsoft Sans Serif",12.0,System::Drawing::FontStyle::Bold );
MessageBox::Show( String::Format( "Before Font Change: {0}\nAfter Font Change: {1}", varPrefHeight1, numericUpDown1->PreferredHeight ) );
}
private void numericUpDown1_Leave(Object sender,
EventArgs e)
{
/* If the entered value is greater than Minimum or Maximum,
select the text and open a message box. */
if((System.Convert.ToInt32(numericUpDown1.Text) > numericUpDown1.Maximum) ||
(System.Convert.ToInt32(numericUpDown1.Text) < numericUpDown1.Minimum))
{
MessageBox.Show("The value entered was not between the Minimum and" +
"Maximum allowable values." + "\n" + "Please re-enter.");
numericUpDown1.Focus();
numericUpDown1.Select(0, numericUpDown1.Text.Length);
}
}
private void button1_Click(Object sender,
EventArgs e)
{
int varPrefHeight1;
/* Capture the PreferredHeight before and after the Font
is changed, and display the results in a message box. */
varPrefHeight1 = numericUpDown1.PreferredHeight;
numericUpDown1.Font = new System.Drawing.Font("Microsoft Sans Serif",
12F, System.Drawing.FontStyle.Bold);
MessageBox.Show("Before Font Change: " + varPrefHeight1.ToString() +
"\n" + "After Font Change: " + numericUpDown1.PreferredHeight.ToString());
}
Private Sub numericUpDown1_Leave(sender As Object, e As EventArgs)
' If the entered value is greater than Minimum or Maximum,
' select the text and open a message box.
If (System.Convert.ToInt32(numericUpDown1.Text) > numericUpDown1.Maximum) Or _
(System.Convert.ToInt32(numericUpDown1.Text) < numericUpDown1.Minimum) Then
MessageBox.Show("The value entered was not between the Minimum and " & _
"Maximum allowable values." & Microsoft.VisualBasic.ControlChars.Cr & _
"Please re-enter.")
numericUpDown1.Focus()
numericUpDown1.Select(0, numericUpDown1.Text.Length)
End If
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim varPrefHeight1 As Integer
' Capture the PreferredHeight before and after the Font
' is changed, and display the results in a message box.
varPrefHeight1 = numericUpDown1.PreferredHeight
numericUpDown1.Font = New System.Drawing.Font("Microsoft Sans Serif", _
12F, System.Drawing.FontStyle.Bold)
MessageBox.Show("Before Font Change: " & varPrefHeight1.ToString() & _
Microsoft.VisualBasic.ControlChars.Cr & "After Font Change: " & _
numericUpDown1.PreferredHeight.ToString())
End Sub
注解
UpdateEditText如果在Text将 属性设置为 时设置了 属性true
,UserEdit则调用 方法。
ValidateEditText如果在Text将 属性设置为 时设置了 属性false
,UserEdit则调用 方法。