2013-04-04 47 views
-1

我正在尝试运行时的属性值。首先,我试图用一个人的名称属性来做到这一点,但我不知道如何完成下面的if语句。我希望它重新打开我的Form2,它将学生作为一个参数,并显示他们的所有细节。任何帮助或建议将不胜感激。如果我完全做错了,请告诉我一些关于如何在运行时编辑属性数据的指导或建议。按钮以返回对属性所做的更改?

public class Student :IPerson 
{ 
    //Method that changes the original name 
    public string ChangeName(string newForename) 
    { 
     _forename = newForename; 
     return _forename; 
    } 
} 

public partial class Edit_Details : Form 
{  
    public Edit_Details(Student student) 
    { 
     InitializeComponent(); 
     nameLabel.Text = student.Forename; 
     student.ChangeName(editNameTextBox.Text); 
     //if(savebutton.Click) //how can I get this to replace the old name with the new one when the button is pressed?? 
    } 
} 
+0

需要每当按钮被点击该事件将触发一个事件连接多达savebutton.Click,然后。在这种情况下,你会想要做一些事情,比如你已经有了ChangeName。 – Eluvatar 2013-04-04 22:54:54

回答

0

public Edit_Details(Student student) 
    { 
     InitializeComponent(); 
     nameLabel.Text = student.Forename; 
     savebutton.Click+=(sender,e)=> 
      { 
      savebutton.Text=student.ChangeName(editNameTextBox.Text); 
      }; 
    } 
+0

非常感谢。这很有效,除了我使用了新的Student(student.ChangeName(editNameTextBox.Text),而不是savebutton.Text = student.ChangeName(editNameTextBox.Text); – Kash 2013-04-04 23:02:35

+0

这是我的荣幸。 – 2013-04-04 23:05:18