How do I add a class to a WinForms project?
I am trying to add a class to a WinForms project and put my code inside it. However, it causes problems such as scope problems and conflicts at loading the controls
private void InitializeComponent()
{
this.SuspendLayout();
//
// Chess
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Chess";
this.Load += n开发者_StackOverflow中文版ew System.EventHandler(this.Chess_Load_1);
this.ResumeLayout(false);
}
private void Chess_Load_1(object sender, EventArgs e)
{
}
When I add a class, it puts me that automatically and I cant prevent that (it does so as soon as I copy and paste my code to the newly class created, as soon as I move the static main function out of newly pasted code. Than it gives me this error:
Error 1 The item "obj\Debug\WindowsFormsApplication1.Chess.resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter. ChessBoardGame
You can define classes after the declaration of Form finishes. You may get an warning if you try to define it before the Form class definition. It should not cause any problem otherwise.
-Be sure about what you name your class. -If it is is folders be careful about the folder name as well.
If the names are in use it will not work fine.
For more, you will need to provide more information or even a screen picture.
EDIT: It's a problem with copy paste. check this link Same error
精彩评论