NUmericupdown控件


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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM