NumericUpDown.Maximum 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置数字显示框(也称作 up-down 控件)的最大值。
public:
property System::Decimal Maximum { System::Decimal get(); void set(System::Decimal value); };
public decimal Maximum { get; set; }
member this.Maximum : decimal with get, set
Public Property Maximum As Decimal
属性值
数字显示框的最大值。 默认值为 100。
示例
下面的代码示例创建并初始化控件 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
注解
Maximum设置 属性后,将Minimum计算 属性并UpdateEditText调用 方法。 Minimum如果属性大于新Maximum属性,则Minimum属性值设置为等于 Maximum 值。 如果当前 Value 值大于新 Maximum 值,则为 。 属性值 Value 设置为等于 Maximum 值。