UpDownBase.Text Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Pobiera lub ustawia tekst wyświetlany w polu pokrętła (znany również jako kontrolka w górę w dół).
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
Wartość nieruchomości
Wartość ciągu wyświetlana w polu pokrętła.
Przykłady
W poniższym przykładzie kodu użyto klasy NumericUpDownpochodnej . Ten kod wymaga, aby kontrolka NumericUpDown i element Button zostały utworzone w formularzu, a System.Drawing przestrzeń nazw została dodana jako odwołanie. Click Po zdarzeniu przycisku zwiększa się rozmiar punktu tekstu w kontrolceNumericUpDown. Spowoduje to wyświetlenie monitu kontrolki o dostosowanie jej PreferredHeight właściwości, aby cały tekst był widoczny w kontrolce. Gdy użytkownik wprowadzi nową wartość i opuści kontrolkę NumericUpDown , tekst zostanie przekonwertowany na wartość liczbową z wartości ciągu i zostanie zweryfikowany jako między wartościami Minimum i Maximum . Jeśli wartość jest nieprawidłowa, MessageBox zostanie wyświetlony błąd, a Select metoda wybierze tekst, aby użytkownik mógł wprowadzić nową wartość.
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
Uwagi
Metoda jest wywoływana UpdateEditText , Text jeśli właściwość jest ustawiona, gdy właściwość jest ustawiona UserEdit na truewartość . Metoda jest wywoływana ValidateEditText , Text jeśli właściwość jest ustawiona, gdy właściwość jest ustawiona UserEdit na falsewartość .