다음을 통해 공유


UpDownBase.Text 속성

정의

스핀 상자에 표시되는 텍스트를 가져오거나 설정합니다(업다운 컨트롤이라고도 함).

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 설정된 경우 메서드가 UserEdit 호출됩니다 true. 속성 ValidateEditText 이 설정된 동안 속성이 Text 설정된 경우 메서드가 UserEdit 호출됩니다 false.

적용 대상

추가 정보