按钮返回对属性所做的更改?

时间:2013-04-04 22:50:41

标签: c# winforms button methods properties

我正在尝试运行时的属性值。首先,我尝试使用一个人的name属性,但我不知道如何完成下面的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??
    }
}

1 个答案:

答案 0 :(得分:0)

in

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