Regarding the type "**.FormMain" in VS, a member named "InitializeComponent" has been defined, and its members have the same parameter type. "Problem handling

1. Problem description

In the development process, sometimes we may refer to the form files of other projects in the newly created vs project in order to save time. During the reference process, there may be something similar to: Type "**.FormMain" has been defined. The member named'InitializeComponent', its members have the same parameter type "problem

2. Analysis of the cause of the problem

The main reason for this kind of problem is that the way to add files to the project is wrong. For example, in vs2012, multiple files are selected at the same time when adding, as shown in the following figure:

After adding files, you need to modify the namespace name to be consistent with the current project.

In the vs project solution manager window, you will see that the first two files are not in a superior-subordinate relationship, but have become a side-by-side relationship. Therefore, the above error will appear, and you will not see any problems with the code after repeated viewing.

3. Solution

The solution to the above problem is actually very simple. Change the method of adding references to the windows form program, that is, do not select all the files of this form program when adding, just select the Mainfrm.cs file to add in, and then update and save the project. Other corresponding files will be automatically added to the project, this problem is solved.

At the same time, remember to modify the namespace name to be consistent with the current project.

Guess you like

Origin blog.csdn.net/soderayer/article/details/114382081