我正在使用visual studio并且有一些numericUpDown控件,我已经为(min,max,value和increment)设置了值。代码设计器不断将我的简单十进制值转换为int []。我知道它说“不要用代码编辑器修改这个方法的内容”但我觉得在这里调整属性真的很有用,我觉得当我改变时我只是“把事情做得很好”:
this.numericUpDown1.Increment = new decimal(new int[] {
2,
0,
0,
0});
到
this.numericUpDown1.Increment = new decimal(2);
但是,如果我触摸视觉表单设计器上的控件,它会将其更改回来。我想也许有一个标志会一直保留,直到我希望它更新。它更多的是可读性和导航性,但即使它只是让它在一条线上,我也会更开心。
我发现这个(How can I tell Visual Studio to not populate a field in the designer code?)有人试图离开它,但我不确定它是否适用于此情况。
随意告诉我,我应该克服它而不管它!
答案 0 :(得分:1)
您可以创建自己的NumericUpDown用户控件。只需继承常用的NumeriUpDown,并在构造函数中设置所需的属性。
public partial class MyUpDownCtrl : NumericUpDown
{
public MyUpDownCtrl()
{
InitializeComponent();
this.Increment = new decimal(2);
}
}
生成解决方案后,您可以在工具箱中使用新的自定义UpDownControl,只需将其拖动就像普通的numericUpDown一样。
我希望它对您有所帮助,因为我不知道如何让Visual Studio停止自动更改表单设计器代码。也许它根本无法完成。
答案 1 :(得分:1)
刚刚意识到(感谢@Jonathan)我可以在设计器ABOVE中创建一个单独的部分......这意味着只要我不想改变,我就可以将所有默认值放在一个单独的部分中表单设计器上的默认值。这是上面InitializeComponent()
的方法private void IntializeOtherComponents()
{
this.numericUpDown1.Value = new decimal(17);
this.numericUpDown1.Maximum = new decimal(7777);
this.numericUpDown1.Minimum = new decimal(5);
}