C#,Visual Studio中的错误

时间:2017-02-03 18:08:34

标签: c# visual-studio visual-studio-2015

我对编码非常陌生,但我有兴趣所以决定去社区大学上课。我正在完成一项基本任务,为我选择的三个单词创建一个语言翻译器。我跟着我的书,但仍然得到了错误。我已复制下面的代码和错误,并感谢任何指导。

    -- using System;

namespace Language_Translator_Latin
{
partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    )
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.button3 = new System.Windows.Forms.Button();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(21, 112);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(85, 21);
        this.button1.TabIndex = 0;
        this.button1.Text = "Hello";
        this.button1.UseVisualStyleBackColor = true;
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(149, 112);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(85, 21);
        this.button2.TabIndex = 1;
        this.button2.Text = "Happy";
        this.button2.UseVisualStyleBackColor = true;
        // 
        // button3
        // 
        this.button3.Location = new System.Drawing.Point(288, 112);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(85, 21);
        this.button3.TabIndex = 2;
        this.button3.Text = "Good night";
        this.button3.UseVisualStyleBackColor = true;
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(81, 41);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(201, 13);
        this.label1.TabIndex = 3;
        this.label1.Text = "Select a word and I will convert it to Latin";
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(198, 76);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(35, 13);
        this.label2.TabIndex = 4;
        this.label2.Text = "label2";
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(431, 164);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.button3);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
}
}
private void HelloButton_Click(object sender, EventArgs e)
{
translationLabel.Text = "Salve";
}
private void HappyButton_Click(object sender, EventArgs e)
{
translationLabel.Text = "Laeta";
}
private void GoodnightButton_Click(object sender, EventArgs e)
{
translationLabel.Text = "Bonum nox"

错误:

1 个答案:

答案 0 :(得分:0)

不太清楚你得到的错误,你的问题的那部分现在是空白的。

我确实看到了“private void HelloButton”的位置和向下的问题,它似乎在类本身之外。

你有两条线 } }

在我提到的部分正上方,它应该只有一个}后跟你的私有void HelloButton。然后在最后你错过了一个},加上结束}。

这是一个更接近你想要的东西。我没有你所有的代码所以只清理了最终部分。你需要更加谨慎地匹配{和}。另一件事是#endregion的位置,它应该与它所引用的自动代码保持同步。

// 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(431, 164);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.button3);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    #endregion

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;

    private void HelloButton_Click(object sender, EventArgs e)
    {
        translationLabel.Text = "Salve";
    }
    private void HappyButton_Click(object sender, EventArgs e)
    {
        translationLabel.Text = "Laeta";
    }
    private void GoodnightButton_Click(object sender, EventArgs e)
    {
        translationLabel.Text = "Bonum nox";
    }
}

}