一、数值选择控件说明
数值选择控件又称为数值选择控件,是一个显示和输入数值的控件,控件提供了一对上下箭头,主要作用是将一个数按一定的值进行增加或减少。
二、数值选择控件属性
它主要有四个常用的属性:
(1)Increment属性表示每次单击按钮时增加或者减少的量。
(2)Maximum属性表示最大值。
(3)Minumum属性表示最小值。
(4)Value属性表示当前值。
注意:如果想要使NumericUpDown控件的值发生更改时,就会响应事件ValueChange。编写程序,向窗体添加NumbericUpDown控件,并使用Label控件在ValueChange事件中输出当前值。
三、数值选择控件实例
1、添加NumberiUpDown和Label的两个控件。
2、Form1控件发生Load事件:
private void Forml Load(object sender, EventArgs e)
{
private void Forml Load(object sender, EventArgs e)
{
numericUpDown1.Maximum=50;//设置控件的最大值为50
numericUpDown1.Minimum=0;//设置控件的最小值为0
numericUpDown1.Increment=5;//设置单击该银时增加或者减少的值为5
}
}
3、numbericUpDown1控件发生ValueChanged事件:
private void numericUpDown1 Valuechanged(object sender, EventArgs e)
{
label1.Text ="当前值为:"+ numericUpDown1.Value;
}
4、运行结果如下:
完整代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using system.Drawing;
using System.Ling;
using System.Text;
using System.Threading.Tasks;
using System.windows.Forms;
namespace windowsFormsApp1
{
public partial class Form1 :Form
{
public Form1()
{
InitializeComponent();
}
}
private void Forml Load(object sender, EventArgs e)
{
private void Forml Load(object sender, EventArgs e)
{
numericUpDown1.Maximum=50;//设置控件的最大值为50
numericUpDown1.Minimum=0;//设置控件的最小值为0
numericUpDown1.Increment=5;//设置单击该银时增加或者减少的值为5
}
}
private void numericUpDown1 Valuechanged(object sender, EventArgs e)
{
label1.Text ="当前值为:"+ numericUpDown1.Value;
}
}