共用方式為


如何:使用 Windows Form NumericUpDown 控制項設定和傳回數值

Windows Forms NumericUpDown 控制項的數值由其 Value 屬性決定。 您可以為該控制項的值撰寫條件式測試,就像任何其他屬性一樣。 設定 Value 屬性後,您可以透過撰寫程式碼對其執行作業來直接調整它,也可以呼叫 UpButtonDownButton 方法。

若要設定數值

  1. 在程式碼中或 [屬性] 視窗中為 Value 屬性指派一個值。

    NumericUpDown1.Value = 55
    
    numericUpDown1.Value = 55;
    
    numericUpDown1->Value = 55;
    

    -或-

  2. 呼叫 UpButtonDownButton 方法,按 Increment 屬性中指定的量來增加或減少該值。

    NumericUpDown1.UpButton()
    
    numericUpDown1.UpButton();
    
    numericUpDown1->UpButton();
    

若要傳回數值

  • 存取程式碼中的 Value 屬性。

    If NumericUpDown1.Value >= 65 Then
       MessageBox.Show("Age is: " & NumericUpDown1.Value.ToString)
    Else
       MessageBox.Show("The customer is ineligible for a senior citizen discount.")
    End If
    
    if(numericUpDown1.Value >= 65)
    {
       MessageBox.Show("Age is: " + numericUpDown1.Value.ToString());
    }
    else
    {
       MessageBox.Show("The customer is ineligible for a senior citizen discount.");
    }
    
    if(numericUpDown1->Value >= 65)
    {
       MessageBox::Show(String::Concat("Age is: ",
          numericUpDown1->Value.ToString()));
    }
    else
    {
       MessageBox::Show
          ("The customer is ineligible for a senior citizen discount.");
    }
    

另請參閱