Prevent Auto code change in Designer.cs for a specific line

后端 未结 1 1180
时光说笑
时光说笑 2021-01-27 03:21

I made a simple change in Designer.cs which is

this.dateTimePicker.MaxDate = DateTime.Now;

but whenever i do some change in form design

相关标签:
1条回答
  • 2021-01-27 04:09

    You should not change code in the InitializeComponent method as it is auto-generated and will be replaced when you make changes in the designer. The method summary says it all:

    do not modify the contents of this method with the code editor

    Place your code in the constructor of your code-behind file instead (after the call to InitializeComponent). This will set the value and override any value that may have been specified in the InitializeComponent method:

    using System;
    using System.Windows.Forms;
    
    namespace Bling
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                dateTimePicker.MaxDate = DateTime.Now;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题