다음을 통해 공유


NumericUpDown 클래스

숫자 값을 표시하는 Windows 스핀 상자(up-down 컨트롤이라고도 함)를 나타냅니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class NumericUpDown
    Inherits UpDownBase
    Implements ISupportInitialize
‘사용 방법
Dim instance As NumericUpDown
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class NumericUpDown : UpDownBase, ISupportInitialize
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class NumericUpDown : public UpDownBase, ISupportInitialize
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class NumericUpDown extends UpDownBase implements ISupportInitialize
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class NumericUpDown extends UpDownBase implements ISupportInitialize

설명

NumericUpDown 컨트롤에는 컨트롤의 위로 또는 아래로 단추를 클릭하여 증가 또는 감소시킬 수 있는 단일 숫자 값이 들어 있습니다. ReadOnly 속성이 true로 설정되어 있지 않으면 값을 입력할 수도 있습니다.

숫자 표시 형식은 DecimalPlaces, Hexadecimal 또는 ThousandsSeparator 속성을 설정하여 지정합니다. 컨트롤에 16진수 값을 표시하려면 Hexadecimal 속성을 true로 설정합니다. 1000 이상인 10진수에 1000 단위 구분 기호를 표시하려면 ThousandsSeparator 속성을 true로 설정합니다. 소수점 기호 뒤에 표시되는 자릿수를 지정하려면 DecimalPlaces 속성을 표시할 소수 자릿수로 설정합니다.

컨트롤에 사용할 수 있는 값의 범위를 지정하려면 MinimumMaximum 속성을 설정합니다. 위로 또는 아래로 단추를 클릭할 때 값이 Value 속성의 값까지 증가 또는 감소하도록 지정하려면 Increment 값을 설정합니다. Accelerations 속성을 설정하여 사용자가 위쪽 또는 아래쪽 화살표를 계속 누르고 있을 때 컨트롤에서 숫자를 이동하는 속도를 증가시킬 수 있습니다.

UpButton 또는 DownButton 메서드가 호출되면 코드에서 새 값의 유효성을 검사하거나 위로 또는 아래로 단추를 클릭하여 유효성을 검사한 다음 컨트롤을 적절한 형식의 새 값으로 업데이트합니다. 특히 UserEdit 속성이 true로 설정되어 있으면 값의 유효성을 검사하거나 값을 업데이트하기 전에 ParseEditText 메서드가 호출됩니다. 그런 다음 이 값이 MinimumMaximum 사이의 값인지 확인되고 UpdateEditText 메서드가 호출됩니다.

예제

다음 코드 예제에서는 NumericUpDown 컨트롤을 만들어 초기화하고 해당 공용 속성 중 일부를 설정한 다음 사용자가 런타임에 이러한 속성 중 일부를 변경할 수 있도록 합니다. 이 코드는 세 개의 CheckBox 컨트롤이 폼에 배치되고 Click 이벤트에 대한 처리기가 인스턴스화된 것으로 가정합니다. DecimalPlaces, ThousandsSeparatorHexadecimal 속성은 각 확인란의 Click 이벤트에 대해 설정됩니다.

Public Sub InstantiateMyNumericUpDown()
    ' Create and initialize a NumericUpDown control.
    numericUpDown1 = New NumericUpDown()
    
    ' Dock the control to the top of the form.
    numericUpDown1.Dock = System.Windows.Forms.DockStyle.Top
    
    ' Set the Minimum, Maximum, and initial Value.
    numericUpDown1.Value = 5
    numericUpDown1.Maximum = 2500
    numericUpDown1.Minimum = - 100
    
    ' Add the NumericUpDown to the Form.
    Controls.Add(numericUpDown1)
End Sub    

' Check box to toggle decimal places to be displayed.
Private Sub checkBox1_Click(sender As Object, e As EventArgs)
    ' If DecimalPlaces is greater than 0, set them to 0 and round the
    ' current Value; otherwise, set DecimalPlaces to 2 and change the
    ' Increment to 0.25. 
    If numericUpDown1.DecimalPlaces > 0 Then
        numericUpDown1.DecimalPlaces = 0
        numericUpDown1.Value = Decimal.Round(numericUpDown1.Value, 0)
    Else
        numericUpDown1.DecimalPlaces = 2
        numericUpDown1.Increment = 0.25D
    End If
End Sub    

' Check box to toggle thousands separators to be displayed.
Private Sub checkBox2_Click(sender As Object, e As EventArgs)
    ' If ThousandsSeparator is true, set it to false;
    ' otherwise, set it to true. 
    If numericUpDown1.ThousandsSeparator Then
        numericUpDown1.ThousandsSeparator = False
    Else
        numericUpDown1.ThousandsSeparator = True
    End If
End Sub    

' Check box to toggle hexadecimal to be displayed.
Private Sub checkBox3_Click(sender As Object, e As EventArgs)
    ' If Hexadecimal is true, set it to false;
    ' otherwise, set it to true. 
    If numericUpDown1.Hexadecimal Then
        numericUpDown1.Hexadecimal = False
    Else
        numericUpDown1.Hexadecimal = True
    End If
End Sub
public void InstantiateMyNumericUpDown()
{
   // Create and initialize a NumericUpDown control.
   numericUpDown1 = new NumericUpDown();

   // Dock the control to the top of the form.
   numericUpDown1.Dock = System.Windows.Forms.DockStyle.Top;

   // Set the Minimum, Maximum, and initial Value.
   numericUpDown1.Value = 5;
   numericUpDown1.Maximum = 2500;
   numericUpDown1.Minimum = -100;
   
   // Add the NumericUpDown to the Form.
   Controls.Add(numericUpDown1);
}

// Check box to toggle decimal places to be displayed.
private void checkBox1_Click(Object sender,
                             EventArgs e)
{
   /* If DecimalPlaces is greater than 0, set them to 0 and round the 
      current Value; otherwise, set DecimalPlaces to 2 and change the 
      Increment to 0.25. */
   if (numericUpDown1.DecimalPlaces > 0)
   {
      numericUpDown1.DecimalPlaces = 0;
      numericUpDown1.Value = Decimal.Round(numericUpDown1.Value, 0);
   }
   else
   {
      numericUpDown1.DecimalPlaces = 2;
      numericUpDown1.Increment = 0.25M;
   }
}

// Check box to toggle thousands separators to be displayed.
private void checkBox2_Click(Object sender,
                             EventArgs e)
{   
   /* If ThousandsSeparator is true, set it to false; 
      otherwise, set it to true. */
   if (numericUpDown1.ThousandsSeparator)
   {
      numericUpDown1.ThousandsSeparator = false;
   }
   else
   {
      numericUpDown1.ThousandsSeparator = true;
   }
}

// Check box to toggle hexadecimal to be displayed.
private void checkBox3_Click(Object sender, 
                             EventArgs e)
{
   /* If Hexadecimal is true, set it to false; 
      otherwise, set it to true. */    
   if (numericUpDown1.Hexadecimal)
   {
      numericUpDown1.Hexadecimal = false;
   }
   else
   {
      numericUpDown1.Hexadecimal = true;
   }
}
public:
   void InstantiateMyNumericUpDown()
   {
      // Create and initialize a NumericUpDown control.
      numericUpDown1 = gcnew NumericUpDown;
      
      // Dock the control to the top of the form.
      numericUpDown1->Dock = System::Windows::Forms::DockStyle::Top;
      
      // Set the Minimum, Maximum, and initial Value.
      numericUpDown1->Value = 5;
      numericUpDown1->Maximum = 2500;
      numericUpDown1->Minimum = -100;
      
      // Add the NumericUpDown to the Form.
      Controls->Add( numericUpDown1 );
   }

private:
   // Check box to toggle decimal places to be displayed.
   void checkBox1_Click( Object^ sender, EventArgs^ e )
   {
      /* If DecimalPlaces is greater than 0, set them to 0 and round the 
         current Value; otherwise, set DecimalPlaces to 2 and change the 
         Increment to 0.25. */
      if ( numericUpDown1->DecimalPlaces > 0 )
      {
         numericUpDown1->DecimalPlaces = 0;
         numericUpDown1->Value = Decimal::Round( numericUpDown1->Value, 0 );
      }
      else
      {
         numericUpDown1->DecimalPlaces = 2;
         numericUpDown1->Increment = Decimal(0.25);
      }
   }

   // Check box to toggle thousands separators to be displayed.
   void checkBox2_Click( Object^ sender, EventArgs^ e )
   {
      /* If ThousandsSeparator is true, set it to false; 
         otherwise, set it to true. */
      if ( numericUpDown1->ThousandsSeparator )
      {
         numericUpDown1->ThousandsSeparator = false;
      }
      else
      {
         numericUpDown1->ThousandsSeparator = true;
      }
   }

   // Check box to toggle hexadecimal to be displayed.
   void checkBox3_Click( Object^ sender, EventArgs^ e )
   {
      /* If Hexadecimal is true, set it to false; 
         otherwise, set it to true. */
      if ( numericUpDown1->Hexadecimal )
      {
         numericUpDown1->Hexadecimal = false;
      }
      else
      {
         numericUpDown1->Hexadecimal = true;
      }
   }
public void InstantiateMyNumericUpDown()
{
    // Create and initialize a NumericUpDown control.
    numericUpDown1 = new NumericUpDown();

    // Dock the control to the top of the form.
    numericUpDown1.set_Dock(System.Windows.Forms.DockStyle.Top);

    // Set the Minimum, Maximum, and initial Value.
    numericUpDown1.set_Value(System.Convert.ToDecimal(5));
    numericUpDown1.set_Maximum(System.Convert.ToDecimal(2500));
    numericUpDown1.set_Minimum(System.Convert.ToDecimal(-100));

    // Add the NumericUpDown to the Form.
    get_Controls().Add(numericUpDown1);
} //InstantiateMyNumericUpDown

// Check box to toggle decimal places to be displayed.
private void checkBox1_Click(Object sender,EventArgs e)
{
    /*  If DecimalPlaces is greater than 0, set them to 0 and round the 
        current Value; otherwise, set DecimalPlaces to 2 and change the 
        Increment to 0.25.
     */
    if (numericUpDown1.get_DecimalPlaces() > 0) {
        numericUpDown1.set_DecimalPlaces(0);
        numericUpDown1.set_Value(Decimal.Round
            (numericUpDown1.get_Value(), 0));
    }
    else {
        numericUpDown1.set_DecimalPlaces(2);
        numericUpDown1.set_Increment(System.Convert.ToDecimal((0.25)));
    }
} //checkBox1_Click

// Check box to toggle thousands separators to be displayed.
private void checkBox2_Click(Object sender,EventArgs e)
{
    /* If ThousandsSeparator is true, set it to false; 
       otherwise, set it to true.
     */
    if (numericUpDown1.get_ThousandsSeparator()) {
        numericUpDown1.set_ThousandsSeparator(false);
    }
    else {
        numericUpDown1.set_ThousandsSeparator(true);
    }
} //checkBox2_Click

// Check box to toggle hexadecimal to be displayed.
private void checkBox3_Click(Object sender,EventArgs e)
{
    /* If Hexadecimal is true, set it to false; 
       otherwise, set it to true. 
     */
    if (numericUpDown1.get_Hexadecimal()) {
        numericUpDown1.set_Hexadecimal(false);
    }
    else {
        numericUpDown1.set_Hexadecimal(true);
    }
} //checkBox3_Click
function InstantiateMyNumericUpDown(){
  // Create and initialize a NumericUpDown control.
  numericUpDown1 = new NumericUpDown()
  
  // Dock the control to the top of the form.
  numericUpDown1.Dock = System.Windows.Forms.DockStyle.Top
  
  // Set the Minimum, Maximum, and initial Value.
  numericUpDown1.Value = 5
  numericUpDown1.Maximum = 2500
  numericUpDown1.Minimum = - 100
  
  // Add the NumericUpDown to the Form.
  Controls.Add(numericUpDown1)
}    

// Check box to toggle decimal places to be displayed.
function checkBox1_Click(sender : Object, e : EventArgs){
  // If DecimalPlaces is greater than 0, set them to 0 and round the
  // current Value; otherwise, set DecimalPlaces to 2 and change the
  // Increment to 0.25. 
  if(numericUpDown1.DecimalPlaces > 0){
    numericUpDown1.DecimalPlaces = 0
    numericUpDown1.Value = Decimal.Round(numericUpDown1.Value, 0)
  }else{
    numericUpDown1.DecimalPlaces = 2
    numericUpDown1.Increment = 0.25
  }
}    

// Check box to toggle thousands separators to be displayed.
function checkBox2_Click(sender : Object, e : EventArgs){
  // If ThousandsSeparator is true, set it to false;
  // otherwise, set it to true. 
  numericUpDown1.ThousandsSeparator = !numericUpDown1.ThousandsSeparator
}    

// Check box to toggle hexadecimal to be displayed.
function checkBox3_Click(sender : Object, e : EventArgs){
  // If Hexadecimal is true, set it to false;
  // otherwise, set it to true. 
  numericUpDown1.Hexadecimal = !numericUpDown1.Hexadecimal
}

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ContainerControl
             System.Windows.Forms.UpDownBase
              System.Windows.Forms.NumericUpDown

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

NumericUpDown 멤버
System.Windows.Forms 네임스페이스
UpDownBase
ISupportInitialize
DomainUpDown 클래스