UpDownBase.Text 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定微調方塊 (也稱為上下按鈕控制項) 中所顯示的文字。
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 則會呼叫 方法。