2017-02-03 140 views
-1

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

-- 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" 

错误:

+0

你的问题似乎是不完整的。 – brugnner

+0

您需要发布整个代码,以便我们纠正问题。看来你错过了一些代码。 –

+0

第7行的括号是什么? –

回答

0

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

我确实看到了一些与“私人无效HelloButton”放置和向下的问题,它似乎是在课堂之外。

你有两条线,其是 }}

权我所提到的部分上面,它应该只有一个}其次是你的私人无效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"; 
    } 
} 

}

+0

谢谢Trelly! –