nikorio nikorio - 4 years ago 77
C# Question

Up-down control negative value

How to programmatically get Minimum -0.5 negative double value with NumericUpDown, for example in range from -0.5 to 0.5 like this -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5 with increment

numericUpDown2.Increment = 0.1m;
to initialize as value and make it available for spin box which starts from 0.0. or in case of property setting Minimum -0.5, just switches between -0.5 and 0.5

does not makes sense for double to decimal

numericUpDown2.Maximum = 0.5;
numericUpDown2.Minimum = // -0.5;

and same with
numericUpDown2.Minimum = double.MinValue;

Answer Source

Setting the minimum/Maximum is correct as your code is. You are missing two other properties to get the desired behavior. You also need to set the Increment value and the DecimalPlaces value like below. "M" indicates a decimal value. Hope this helps.

numericUpDown1.Increment = 0.1M;
numericUpDown1.DecimalPlaces = 1;
numericUpDown1.Minimum = -0.5M;
numericUpDown1.Maximum = 0.5M;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download