numericUpDown コントロールの精度を 0.5 に設定しました。(0 から 10 まで)
-changed decimalplaces to 1
-changed increment to 0,5
-maximum at 10
-minimum at 0
値が増加すると、次のように表示されます。
0,0
0,5
1,0
1,5
...
10,0
私が欲しいのは:
0
0,5
1
1,5
...
10
これを行う簡単な方法はありますか?ありがとうございました。
numericUpDown コントロールの精度を 0.5 に設定しました。(0 から 10 まで)
-changed decimalplaces to 1
-changed increment to 0,5
-maximum at 10
-minimum at 0
値が増加すると、次のように表示されます。
0,0
0,5
1,0
1,5
...
10,0
私が欲しいのは:
0
0,5
1
1,5
...
10
これを行う簡単な方法はありますか?ありがとうございました。
イベントで処理し、値が丸められた値である場合に比較するプロパティをValueChanged変更できますか。DecimalPlaces
この回答に示されているように、WinformNumericUpDownコントロールとoverrideそのUpdateEditTextメソッドをSO の同様の質問に拡張できます。
クラスは次のようになります。
public class NumericUpDownEx : NumericUpDown
{
public NumericUpDownEx() {
// Optionally set other control properties here.
this.Maximum = 10;
this.Minimum = 0;
this.DecimalPlaces = 1;
this.Increment = ,5m;
}
protected override void UpdateEditText() {
// Remove any trailing ',5'.
this.Text = this.Value.ToString().Replace(".0", string.Empty);
}
}
このアプローチの利点は、他のプロジェクトで使用できる新しいコントロールを作成していることです。