c# - Define maximum for NumerictUpDown in a dictionary -
so have dictionary few controls called controldict. if want set maximum numericupdown control this:
controldict.add("amountnum" + i.tostring(), new numericupdown()); controldict["amountnum" + i.tostring()].location = new point(60, 42); controldict["amountnum" + i.tostring()].maximum = new decimal(new int[] { -1, -1, -1, 0}); it gives me error:
'control' not contain definition 'maximum' , no extension method 'maximum' accepting first argument of type 'control' found (are missing using directive or assembly reference?)
how can solve this?
you should cast control numericupdown assign values properties:
var numeric = (numericupdown)controldict["amountnum" + i.tostring()]; numeric.maximum = 100; why
controldict["amountnum" + i.tostring()].locationworks without casting?
because result control , control class has location property. , of controls including numericupdown inherited control.
items of dictionary of type control. when item dictionary using controldict["key"] result of type control. can access properties of control class. when know result control specific control type, have access specific control properties should cast specific control type.
Comments
Post a Comment