在声明"..此类型的另一个部分声明中缺少部分修饰符".我是一个初学者,只是在跟着这本书 [英] Missing partial modifier on declaration ..another partial declaration of this type exists". I'm a beginner and just following the book

查看:351
本文介绍了在声明"..此类型的另一个部分声明中缺少部分修饰符".我是一个初学者,只是在跟着这本书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者,我正在做一本书之后的练习.下面是我的代码,我得到了

I'm a beginner and I'm doing an exercise following a book. Below is my code and i got this

"Missing partial modifier on declaration of type 'Windowsform.Form1'; another partial declaration of this type exists".

我该怎么办?我的代码如下:

using System;
using System.Windows.Forms;

namespace Windowsform
{
    public class Form1 : Form
    {
       private TextBox txtEnter;
       private Label lblDisplay;
       private Button btnOk;

       public Form1()

       {
           this.txtEnter = new TextBox();
           this.lblDisplay = new Label();
           this.btnOk = new Button();
           this.Text = "My Hellowin app!";


           //txtEnter
           this.txtEnter.Location = new System.Drawing.Point(16, 32);
           this.txtEnter.Size = new System.Drawing.Size(264, 20);

           //lblDisplay
           this.lblDisplay.Location = new System.Drawing.Point(16, 72);
           this.lblDisplay.Size = new System.Drawing.Size(264, 128);

           //btnOK
           this.btnOk.Location = new System.Drawing.Point(88, 224);
           this.btnOk.Text = "OK";
           this.btnOk.Click +=
               new System.EventHandler(this.btnOK_Click); 

           //MyForm
           this.Controls.AddRange(new Control[] {
                            this.txtEnter, this.lblDisplay, this.btnOk});

       }

       static void Main()
       {
           Application.Run(new Form1());
       }

       private void btnOK_Click(object sender, System.EventArgs e)
       {
           lblDisplay.Text = txtEnter.Text + "\n" + lblDisplay.Text;
       }
    }
}

推荐答案

在另一个地方,您声明了一个具有相同名称(Form1)的类,并使用partial修饰符对其进行了声明.

In another place you declared a class with the same name (Form1) and there it's declared with the partial modifier.

如果要将类分为两个不同的文件(例如,此文件用于UI布局,另一个文件用于逻辑),则只需将partial修饰符添加到声明中:

If you're splitting your class into two different files (for example this file for UI layout and another file for logic) then simply add the partial modifier to the declaration:

public partial class Form1
{
}

这篇关于在声明"..此类型的另一个部分声明中缺少部分修饰符".我是一个初学者,只是在跟着这本书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆