NUmericupdown控件

本文介绍了Numericupdown控件的基本使用方法,包括如何通过设置属性来改变数值的增减步长、数值范围及小数点精度等。此外,还提供了具体的C#代码示例,演示了如何响应数值变化并更新界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Numericupdown控件是由system.windows.froms.Numericupdown类提供的,主要作用是一个数按一定的值进行增加或减少主要四个常用属性

 

Increment                每次单击按钮时增加或者减少的量

Maximum 最大值

Minimum 最小值

Value 当前值

decimalPlaces             显示小数的位数

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Numericupdown
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label3.Text = "设置值的增量";
            button1.Text = "增加";
            button2.Text = "减少";
            label1.Text = "0";
            numericUpDown1.Maximum = 10000;
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            label1.Text = numericUpDown1.Value.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            numericUpDown1.UpButton();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            numericUpDown1.DownButton();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                numericUpDown1.Increment = int.Parse(textBox2.Text);
            }
            catch 
            {
                MessageBox.Show("格式错误");
            }
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                numericUpDown1.DecimalPlaces = int.Parse(textBox1.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message); 
               
            }
            
        }
    }
}

  

转载于:https://www.cnblogs.com/xiaowie/p/8624291.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值