本文整理汇总了C#中System.Windows.Forms.NumericUpDown.DecimalPlaces属性的典型用法代码示例。如果您正苦于以下问题:C# NumericUpDown.DecimalPlaces属性的具体用法?C# NumericUpDown.DecimalPlaces怎么用?C# NumericUpDown.DecimalPlaces使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.NumericUpDown
的用法示例。
在下文中一共展示了NumericUpDown.DecimalPlaces属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstantiateMyNumericUpDown
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;
}
}
示例2: NumericUpDowns
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
public class NumericUpDowns : Form
{
NumericUpDown nupdwn;
public NumericUpDowns()
{
Size = new Size(480,580);
nupdwn = new NumericUpDown();
nupdwn.Parent = this;
nupdwn.Location = new Point(50, 50);
nupdwn.Size = new Size(60,20);
nupdwn.Value = 1;
nupdwn.Minimum = -10;
nupdwn.Maximum = 10;
nupdwn.Increment = .25m; // decimal
nupdwn.DecimalPlaces = 2;
nupdwn.ReadOnly = true;
nupdwn.TextAlign = HorizontalAlignment.Right;
nupdwn.ValueChanged += new EventHandler(nupdwn_OnValueChanged);
}
private void nupdwn_OnValueChanged(object sender, EventArgs e)
{
Console.WriteLine(nupdwn.Value);
}
static void Main()
{
Application.Run(new NumericUpDowns());
}
}