Example #1
0
        private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            flowLayoutPanel1.Controls.Clear();

            #region ÖRN 1:
            //if (listBox1.SelectedItem is Kaleci)
            //{
            //    Kaleci kaleci = (Kaleci)listBox1.SelectedItem;
            //    foreach (var item in kaleci.GetType().GetProperties())
            //    {
            //        Label label = new Label();
            //        label.Text = $"{item.Name} : {item.GetValue(kaleci)}";
            //        label.Width = flowLayoutPanel1.Width;
            //        flowLayoutPanel1.Controls.Add(label);
            //    }
            //}
            //else if (listBox1.SelectedItem is Forvet)
            //{
            //    Forvet forvet = (Forvet)listBox1.SelectedItem;
            //    foreach (var item in forvet.GetType().GetProperties())
            //    {
            //        Label label = new Label();
            //        label.Text = $"{item.Name} : {item.GetValue(forvet)}";
            //        label.Width = flowLayoutPanel1.Width;
            //        flowLayoutPanel1.Controls.Add(label);
            //    }
            //}
            #endregion

            if (listBox1.SelectedItem.GetType().GetInterface("IFutbolcu") != null)
            {
                IFutbolcu futbolcu = (IFutbolcu)listBox1.SelectedItem; //cast ettik çünkü futbolcu obje olarak dönüyor ama                                                         listeboxa obje ekleyemeyyiz.

                foreach (var item in futbolcu.GetType().GetProperties())
                {
                    Label label = new Label();
                    label.Width = flowLayoutPanel1.Width;
                    label.Text  = $"{item.Name} : {item.GetValue(futbolcu)}";

                    flowLayoutPanel1.Controls.Add(label);
                }
            }
        }
Example #2
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     //listBox1.SelectedItem.GetType().GetInterface("IFutbolcu") != null -> Listboxtan seçilen elemanın tipini getir ve bu tipinde interface'ini al, Eğer bu eleman "IFutbolcu" interface'inden türemişse
     if (listBox1.SelectedItem != null && listBox1.SelectedItem.GetType().GetInterface("IFutbolcu") != null)
     {
         flowLayoutPanel1.Controls.Clear();
         string classAdi = listBox1.SelectedItem.GetType().Name;
         lblBilgi.Text = classAdi;
         IFutbolcu gelen = (IFutbolcu)listBox1.SelectedItem;
         //MessageBox.Show(gelen.AdiSoyadi);
         foreach (PropertyInfo item in gelen.GetType().GetProperties())
         {
             Label lbl = new Label();
             lbl.Text     = $"{item.Name} : {item.GetValue(gelen, null).ToString()}";
             lbl.AutoSize = false;
             lbl.Width    = flowLayoutPanel1.Width;
             flowLayoutPanel1.Controls.Add(lbl);
         }
     }
 }