private void dinamikMetod(object sender, EventArgs e) { Button dinamikButon = (sender as Button); secilen = dinamikButon.Text; Biletform frm = (Biletform)Application.OpenForms["Biletform"]; frm.label8.Text = secilen; frm.vagonid = (int)comboBox1.SelectedValue; this.Close(); }
void liste() { int sol = 1; //formun sol tarafından atanan değer int alt = 70; // formun üst tarafından atanan değer int bol = 7; // bolme işlemindeki amaç formun boyutuna göre butonları sıralı bir şekilde görebilmek için try { int id = 1; panel1.Controls.Clear(); var query = (from t in db.VagonTips where t.tipID == (int)comboBox1.SelectedValue select new { t.koltuksayisi }).First().koltuksayisi.ToString(); var sayi = int.Parse(query.ToString()); for (int i = 1; i <= sayi; i++) { Button btn = new Button(); btn.Name = i.ToString(); btn.AutoSize = false; btn.Size = new Size(this.Width / bol, this.Height / (bol * 2)); btn.Text = i.ToString(); btn.Font = new Font(btn.Font.FontFamily.Name, 18); btn.Location = new Point(sol, alt); panel1.Controls.Add(btn); sol += btn.Width + 5; if (sol + this.Width / bol > this.Width) { sol = 1; alt += this.Height / (bol * 2) + 5; } btn.Click += new EventHandler(dinamikMetod); } Biletform frm = (Biletform)Application.OpenForms["Biletform"]; seferid = (int)frm.searchLookUpEdit1.EditValue; foreach (Control item in panel1.Controls.Cast <Control>()) { if (Denetle(int.Parse(item.Text), (int)comboBox1.SelectedValue, seferid)) { item.BackColor = Color.Red; item.Enabled = false; } else { item.BackColor = Color.Green; } } } catch (Exception ex) { } }