NumericUpDown.Increment 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置单击向上或向下按钮时,数字显示框(也称作 up-down 控件)递增或递减的值。
public:
property System::Decimal Increment { System::Decimal get(); void set(System::Decimal value); };
public decimal Increment { get; set; }
member this.Increment : decimal with get, set
Public Property Increment As Decimal
属性值
单击数字显示框上的向上或向下按钮时 Value 属性要递增或递减的值。 默认值为 1。
例外
所赋的值不大于或等于零。
示例
下面的代码示例创建并初始化控件 NumericUpDown ,设置其一些常见属性,并允许用户在运行时更改其中一些属性。 此代码假定已将三 CheckBox 个控件放置在窗体上,并且已实例化其 Click 事件的处理程序。 、 DecimalPlacesThousandsSeparator和 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 属性按 属性指定的 Increment 量递增,并接近 属性 Maximum 。 单击向下按钮会使 Value 属性按属性指定的 Increment 量递减,并接近 属性 Minimum 。