Reputation: 708
I'm using visual studio and have some numericUpDown controls that I have set values for (min, max, value and increment). The Code Designer keeps turning my simple decimal values into int[]. I know that it says "do not modify the contents of this method with the code editor" but I find it really useful to adjust properties in here and I thought I was just "making things neat" when I changed:
this.numericUpDown1.Increment = new decimal(new int[] {
2,
0,
0,
0});
to
this.numericUpDown1.Increment = new decimal(2);
but alas, it changes it back if I touch the control on the visual form designer. I thought maybe there was a flag that would leave it as is until I want it to be updated. It is more for readability and navigation but even if it would just leave it on one line I'd be happier.
I've found this (How can I tell Visual Studio to not populate a field in the designer code?) where someone was trying to leave it but I'm not sure if it is applicable in this instance.
Feel free to tell me that I should just get over it and leave it alone!
Upvotes: 4
Views: 2560
Reputation: 708
Just realised (thanks @Jonathan) that I could just create a separate section in the designer ABOVE that place ... this means I can have all my default values in a separate section as long as I don't want to changed the defaults on the form designer. This is the method above InitializeComponent()
private void IntializeOtherComponents()
{
this.numericUpDown1.Value = new decimal(17);
this.numericUpDown1.Maximum = new decimal(7777);
this.numericUpDown1.Minimum = new decimal(5);
}
Upvotes: 2
Reputation: 12025
You could make your own NumericUpDown user control. Just inherit from the common NumeriUpDown and set the dessired properties in the constructor.
public partial class MyUpDownCtrl : NumericUpDown
{
public MyUpDownCtrl()
{
InitializeComponent();
this.Increment = new decimal(2);
}
}
After generating your solution you will have your new custom UpDownControl in your Tool Box ready to use just dragging it like the common numericUpDown.
I hope it help you, because I don't know any way to make Visual Studio stop auto-changing the form designer code. Maybe it can't be done at all.
Upvotes: 1