Can I stop Visual Studio from automatically changing form designer code?

I use visual studio and have several numericUpDown elements for which I set the values ​​for (min, max, value and increment). The code constructor continues to turn my simple decimal values ​​into int []. I know that he says: “Do not change the contents of this method using the code editor,” but it’s very useful for me to set the properties here, and I thought I was just “doing things carefully” when I change:

this.numericUpDown1.Increment = new decimal(new int[] { 2, 0, 0, 0}); 

to

  this.numericUpDown1.Increment = new decimal(2); 

but alas, it changes it if you touch the control of the visual form designer. I thought maybe there is a flag that will leave it as it is until I want to update it. This is more for ease of reading and navigation, but even if he just left it on the same line, I would be happier.

I found this ( How can I tell Visual Studio not to fill in a field in the designer code? ) Where someone tried to leave it, m not sure if it is applicable in this case.

Feel free to tell me that I should just overcome this and leave it alone!

+4
source share
2 answers

I just realized (thanks @Jonathan) that I could just create a separate section in the designer ABOVE that place ... this means that I can have all my default values ​​in a separate section until I want to change the default values for the designer of forms. 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); } 
+1
source

You can create your own custom NumericUpDown element. Just inherit from common NumeriUpDown and set dessired properties in the constructor.

 public partial class MyUpDownCtrl : NumericUpDown { public MyUpDownCtrl() { InitializeComponent(); this.Increment = new decimal(2); } } 

After creating your solution, you will have a new custom UpDownControl in the toolbar, ready to use, just by dragging and dropping it like a regular numericUpDown.

I hope this helps you because I don’t know how to get Visual Studio to stop automatically changing the form designer code. Perhaps this cannot be done at all.

+1
source

All Articles