本文整理汇总了C#中System.Windows.Forms.NumericUpDown.Value属性的典型用法代码示例。如果您正苦于以下问题:C# NumericUpDown.Value属性的具体用法?C# NumericUpDown.Value怎么用?C# NumericUpDown.Value使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.NumericUpDown
的用法示例。
在下文中一共展示了NumericUpDown.Value属性的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: Form1
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.GroupBox GroupBox1;
private System.Windows.Forms.Button cmdApply;
private System.Windows.Forms.NumericUpDown udOpacity;
private System.Windows.Forms.Label Label1;
public Form1() {
InitializeComponent();
}
private void cmdApply_Click(object sender, EventArgs e)
{
this.Opacity = (double)udOpacity.Value / 100;
}
private void InitializeComponent()
{
this.GroupBox1 = new System.Windows.Forms.GroupBox();
this.cmdApply = new System.Windows.Forms.Button();
this.udOpacity = new System.Windows.Forms.NumericUpDown();
this.Label1 = new System.Windows.Forms.Label();
this.GroupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.udOpacity)).BeginInit();
this.SuspendLayout();
//
// GroupBox1
//
this.GroupBox1.Controls.Add(this.cmdApply);
this.GroupBox1.Controls.Add(this.udOpacity);
this.GroupBox1.Controls.Add(this.Label1);
this.GroupBox1.Location = new System.Drawing.Point(12, 89);
this.GroupBox1.Name = "GroupBox1";
this.GroupBox1.Size = new System.Drawing.Size(268, 116);
this.GroupBox1.TabIndex = 5;
this.GroupBox1.TabStop = false;
//
// cmdApply
//
this.cmdApply.Location = new System.Drawing.Point(172, 64);
this.cmdApply.Name = "cmdApply";
this.cmdApply.Size = new System.Drawing.Size(80, 24);
this.cmdApply.TabIndex = 5;
this.cmdApply.Text = "Apply";
this.cmdApply.Click += new System.EventHandler(this.cmdApply_Click);
//
// udOpacity
//
this.udOpacity.Increment = new decimal(new int[] {
5,
0,
0,
0});
this.udOpacity.Location = new System.Drawing.Point(88, 32);
this.udOpacity.Name = "udOpacity";
this.udOpacity.Size = new System.Drawing.Size(48, 21);
this.udOpacity.TabIndex = 4;
this.udOpacity.Value = new decimal(new int[] {
50,
0,
0,
0});
//
// Label1
//
this.Label1.Location = new System.Drawing.Point(20, 36);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(56, 16);
this.Label1.TabIndex = 3;
this.Label1.Text = "Opacity:";
//
// Transparent
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(309, 289);
this.Controls.Add(this.GroupBox1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "Transparent";
this.Text = "Transparent";
this.GroupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.udOpacity)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}