NumericUpDown クラスとは? わかりやすく解説

NumericUpDown クラス

数値表示する Windows スピン ボックス (アップダウン コントロール) を表します

名前空間: 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 コントロールには、上向き矢印ボタンまたは下向き矢印ボタンクリックすることによって、それぞれ増分または減分できる数値1 つ表示されます。ReadOnly プロパティtrue設定されていない場合は、ユーザーが値を入力することもできます

DecimalPlaces プロパティHexadecimal プロパティ、または ThousandsSeparator プロパティ設定することによって、数値表示形式指定できますコントロール16 進数表示するには、Hexadecimal プロパティtrue設定します必要に応じて 10 進数区切り記号表示するには、ThousandsSeparator プロパティtrue設定します小数点の後に表示する桁数指定するには、表示桁数DecimalPlaces プロパティ設定します

コントロール指定できる値の有効範囲指定するには、Minimum プロパティおよび Maximum プロパティ設定しますユーザー上向きまたは下向き矢印ボタンクリックしたときに、Value プロパティ増分または減分する値を指定するには、Increment 値を設定します。Accelerations プロパティ設定すると、ユーザー上向きまたは下向き矢印ボタン長くクリックしたときのコントロール変化速めることができます

UpButton メソッドまたは DownButton メソッドコード内で呼び出され場合や、上向きまたは下向き矢印ボタンクリックによって呼び出され場合は、新しい値が検証されコントロール適切な形式新しい値で更新されます。特に、UserEdit プロパティtrue設定されている場合は、値を検証または更新する前に ParseEditText メソッド呼び出されます。そして、値が Minimum 値と Maximum 値の間にあることが確認され、UpdateEditText メソッド呼び出されます。

使用例使用例

NumericUpDown コントロール作成および初期化し一部の共通プロパティ設定し、これらのプロパティ値をユーザー実行時変更できるようにするコード例次に示します。このコードは、フォーム上に 3 つの CheckBox コントロール配置されていること、それらのコントロールClick イベントハンドラインスタンス化されていることを前提にしています。DecimalPlaces プロパティThousandsSeparator プロパティ、および Hexadecimal プロパティは、各チェック ボックス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) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
NumericUpDown メンバ
System.Windows.Forms 名前空間
UpDownBase
ISupportInitialize
DomainUpDown クラス


このページでは「.NET Framework クラス ライブラリ リファレンス」からNumericUpDown クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からNumericUpDown クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からNumericUpDown クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「NumericUpDown クラス」の関連用語

NumericUpDown クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



NumericUpDown クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS