问题
I have a C# application with a custom control. The custom control class looks like this:
public partial class DetNumericUpDown : UpDownBase
{
public event EventHandler ValueChanged;
/* some public methods */
public DetNumericUpDown() { /* ... */ }
}
Then I have several instances of DetNumericUpDown in a form file Main.cs, placed from the designer. Each of these instances have their own ValueChanged event defined, but instead of placing them in Main.cs I have moved them for clarity to another file OtherFile.cs. The problem is that each time I try to use the windows forms designer on Main.cs it recreates these methods in Main.cs and then complains the methods are defined twice. That only happens with the DetNumericUpDown instances, as I have moved some event methods from other controls into OtherFile.cs and it works fine. What am I doing wrong?
来源:https://stackoverflow.com/questions/37762519/windows-forms-editor-keeps-recreating-an-event-method