// constuctor with contact parameter public frmEdit(Contact edit) { InitializeComponent(); setDetails(edit); imageMethod(); }
private void btnSubmit_Click(object sender, EventArgs e) { if (validData()) { // new contact Contact contact = new Contact(); // set values of new contact contact.Name = txtName.Text; contact.State = txtState.Text; contact.Street = txtStreet.Text; contact.ZipCode = txtZip.Text; contact.City = txtCity.Text; contact.ImageFileName = image.FileName; // send back dialog result and contact info this.Tag = contact; this.DialogResult = DialogResult.OK; } }
// gets details from edit button private void setDetails(Contact update) { txtName.Text = update.Name; txtStreet.Text = update.Street; txtCity.Text = update.City; txtState.Text = update.State; txtZip.Text = update.ZipCode; // check to see if image is null if (update.ImageFileName.Length > 0) { picPhoto.Image = Image.FromFile(update.ImageFileName); } else { picPhoto.Image = null; } }