![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi3_komaru-1.png)
上下に三角のボタンの数値入力ってどうやって作るんだろう?
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
スピンボタンといって、NumericUpDownコントロールで実装することができます。
目次
▲▼スピンボタンで数値を入力できるようにする
![](https://tech.mychma.com/wp-content/uploads/2022/06/image-36.png)
![](https://tech.mychma.com/wp-content/uploads/2022/06/image-36.png)
▲▼ボタン(スピンボタン)は、NumericUpDownコントロールをフォームに配置して実装します。
▲▼をクリックをすることで数値の操作を行うことができます。
NumericUpDownコントロールで入力できる数値の範囲は、プロパティのMinimumプロパティ(最小)とMaximumプロパティで指定できます。
また、Valueプロパティで現在値、Incrementプロパティで増減値を指定できます。
![](https://tech.mychma.com/wp-content/uploads/2022/06/image-37.png)
![](https://tech.mychma.com/wp-content/uploads/2022/06/image-37.png)
チェック!
- ThousandSeparatorプロパティ:trueで3桁ごとの桁区切りでカンマを表示する
- ReadOnlyプロパティ:trueで直接入力を禁止する
スクリプトでスピンボタンの設定を行う
以下は、スクリプトで初期設定を行うサンプルになります。
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown1.Minimum = 0;
numericUpDown1.Maximum = 100;
numericUpDown1.Value = 70;
numericUpDown1.Increment = 2;
}
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi3_normal-1.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi3_normal-1.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi3_normal-1.png)
スピンボタンを実装することができました。
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
![](https://tech.mychma.com/wp-content/uploads/2022/05/hukidashi1_normal.png)
決められた区間の数値を指定させたい場合などに利用すると入力制限もできて便利です。
コメント