当前位置: 首页>>代码示例>>C#>>正文


C# NumericUpDown.Increment属性代码示例

本文整理汇总了C#中System.Windows.Forms.NumericUpDown.Increment属性的典型用法代码示例。如果您正苦于以下问题:C# NumericUpDown.Increment属性的具体用法?C# NumericUpDown.Increment怎么用?C# NumericUpDown.Increment使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.NumericUpDown的用法示例。


在下文中一共展示了NumericUpDown.Increment属性的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;
   }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:67,代码来源:NumericUpDown.Increment

示例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());
  }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:37,代码来源:NumericUpDown.Increment


注:本文中的System.Windows.Forms.NumericUpDown.Increment属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。