CodePanic! > C#.NET Tips > 今ここ
■数値入力の使い方
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());
}
}
}
Copyright © 2008.07 - shougo suzaki
|