示例#1
0
 private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     PictureBox1.Image = Image.FromFile(@"..\..\foto\fotocap.jpg");
     try {
         for (int i = 0; i < lstPerson.Count; i++)
         {
             if ((lstPerson[i].surname + " " + lstPerson[i].name) == ListBox1.SelectedItem.ToString())
             {
                 TextBoxSurname.Text = lstPerson[i].surname;
                 TextBoxName.Text    = lstPerson[i].name;
                 MaskedTBPhone.Text  = lstPerson[i].phone;
                 TextBoxEmail.Text   = lstPerson[i].email;
                 LabelNumber.Text    = lstPerson[i].number.ToString();
                 if (lstPerson[i].picture != "")
                 {
                     PictureBox1.Image    = Image.FromFile(lstPerson[i].picture);
                     PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                 }
                 ButtonAdd.Hide();
                 ButtonCLear.Hide();
                 ButtonSave.Show();
                 ButtonDell.Show();
                 ButtonCancel.Show();
                 break;
             }
         }
     }
     catch (NullReferenceException) { }
 }