数値入力の使い方

NumericUpDownコントロールを使えば数値入力が楽です。
外観と簡単な使い方は次の通りです。

numericupdown

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

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

        private void Form1_Load(object sender, EventArgs e)
        {
            // 初期値
            numericUpDown1.Value = 100;

            // 最小値
            numericUpDown1.Minimum = 0;

            // 最大値
            numericUpDown1.Maximum = 1000;

            // テキストを右側に表示
            numericUpDown1.TextAlign = HorizontalAlignment.Right;

            // 増減の矢印をクリックした際に加算、減算される値
            numericUpDown1.Increment = 10;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(numericUpDown1.Value.ToString());
        }
    }
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)