The thing that was bothering me was:
public class ContactObj
{
:
}
:
public class frmContact : Form
{
:
public ContactObj Contact
{
get
{
return myContactObj;
}
set
{
myContactObj = value;
UpdateGUI();
}
}
:
}
It was the set that was bugging me, because one could have code that written as:
var frm = new frmContact(); var contact = new Contact(); contact.First = "Kahless"; frm.Contact = contact; // Nice! We got to populate the form before display! frm.ShowDialog();
If the user changes the first name to "Alexander" in the GUI, then after the dialog returns, contact.First == "Alexander" even if the user cancels out and the dialog (assuming the dialog has both OK and Cancel buttons.
In my mind, either the Contact class should be a struct (as opposed to a class), or the UpdateObj() call in the form should only be called when OK is pressed (as opposed to for every text change event).
Any which way, though, great tutorial!
This post has been edited by Skydiver: 01 June 2012 - 01:15 PM





MultiQuote





|