다음을 통해 공유


UpDownBase.Select(Int32, Int32) 메서드

정의

스핀 상자에서 시작 위치와 선택할 문자 수를 지정하는 텍스트 범위(업다운 컨트롤이라고도 함)를 선택합니다.

public:
 void Select(int start, int length);
public void Select(int start, int length);
override this.Select : int * int -> unit
Public Sub Select (start As Integer, length As Integer)

매개 변수

start
Int32

선택할 첫 번째 문자의 위치입니다.

length
Int32

선택할 총 문자 수입니다.

예제

다음 코드 예제에서는 파생 클래스 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

설명

Select 스핀 상자가 포커스를 가져오거나 속성이 데이터 유효성 검사에 실패할 때 메서드를 Text 사용할 수 있습니다. 파생 클래스에서 메서드에 ValidateEditText 대한 유효성 검사 코드를 추가할 때 유효성 검사에 실패하면 메서드를 Select 호출합니다.

적용 대상

추가 정보