C#NumberiUpDown数值选择控件的用法

  一、数值选择控件说明

数值选择控件又称为数值选择控件,是一个显示和输入数值的控件,控件提供了一对上下箭头,主要作用是将一个数按一定的值进行增加或减少。

 二、数值选择控件属性

  它主要有四个常用的属性:

(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;
    }
}

  • 12
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值