数値コントロールのValue/Decimal/Integerプロパティの型が4.0J以前のバージョンと異なります

文書番号 : 38332     文書種別 : 使用方法     登録日 : 2015/05/27     最終更新日 : 2015/05/27
文書を印刷する
対象製品
InputMan for Windows Forms 8.0J
詳細
4.0J以前の数値コントロール(Number)と5.0J以降の数値コントロール(GcNumber)では、Value、DecimalおよびIntegerプロパティの型が異なります。

プロパティ名 4.0J以前の型 5.0J以降の型
Value Object Null許容のNullable<Decimal>
(Visual BasicではNullable(Of Decimal))
Decimal Decimal
Integer

Nullable型についてはMSDNをご参照ください。

Nullable(Of T) 構造体

このため、4.0J以前と8.0JではValue/Decimal/Integerプロパティの扱い方や動作が異なります。

8.0JでDecimal型の値を取得する場合には、Nullable型のValueプロパティを使用するか、Decimal型へ明示的に変換します。
次のサンプルコードは、いずれも同じDecimal型の値を取得します。

[Visual Basic]
Dim dec1 As Decimal = GcNumber1.Value.Value
Dim dec2 As Decimal = CDec(GcNumber1.Value)
Dim dec3 As Decimal = CType(GcNumber1.Value, Decimal)
[C#]
decimal dec1 = gcNumber1.Value.Value;
decimal dec2 = (decimal)gcNumber1.Valuel;

また、小数点を含む値を設定する場合も、明示的にDecimal型またはNullable<Decimal>型を設定する必要があります。
次のサンプルコードは、数値コントロールの値に1.5を設定します。

[Visual Basic]
GcNumber1.Value = 1.5D
GcNumber2.Value = CDec(1.5)
GcNumber3.Value = CType(1.5, Decimal?)
[C#]
gcNumber1.Value = 1.5m;
gcNumber2.Value = (decimal?)1.5;