NumericUpDown.Value プロパティ

定義

スピン ボックス (アップダウン コントロール) に割り当てる値を取得または設定します。

public:
 property System::Decimal Value { System::Decimal get(); void set(System::Decimal value); };
[System.ComponentModel.Bindable(true)]
public decimal Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : decimal with get, set
Public Property Value As Decimal

プロパティ値

NumericUpDown コントロールに表示する数値。

属性

例外

代入された値は Minimum プロパティ値未満です。

- または -

代入された値が Maximum プロパティ値より大きいです。

次のコード例では、コントロールを NumericUpDown 作成して初期化し、その共通プロパティの一部を設定し、実行時にこれらのプロパティの一部を変更できるようにします。 このコードでは、3 つの CheckBox コントロールがフォームに配置され、イベント Click のハンドラーがインスタンス化されていることを前提としています。 ThousandsSeparatorDecimalPlaces、および Hexadecimal の各プロパティは、各チェック ボックスのイベントにClick設定されます。

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.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 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

注釈

プロパティがValue設定されると、新しい値が と Maximum の値のMinimum間であることが検証されます。 この後、 メソッドを UpdateEditText 呼び出して、スピン ボックスの表示を適切な形式の新しい値で更新します。

適用対象

こちらもご覧ください