2013-04-04 23 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

相關問題