private void FillColorComboBox(DynamicControls cmbbx, List <string> items) { cmbbx.color.Items.Clear(); foreach (var item in items) { cmbbx.color.Items.Add(item); } }
private void button3_Click(object sender, System.EventArgs e) { Debugger.Log($"{dyncontrol.Count}"); Debugger.Log($"{dyncontrol[0].name.Text}"); if (dyncontrol.Count <= 9) { DynamicControls lastItem = dyncontrol[dyncontrol.Count - 1]; int index = dyncontrol.Count; // Dynamic PictureBox PictureBox pctbx = new PictureBox(); pctbx.Name = $"pctbx_{index}"; pctbx.Size = new Size(50, 50); pctbx.Location = new Point(lastItem.image.Location.X, lastItem.image.Location.Y + spaceBetween); pctbx.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(38)))), ((int)(((byte)(66)))), ((int)(((byte)(117))))); Controls.Add(pctbx); // Dynamic ComboBox for Name ComboBox cmbbx_name = new ComboBox(); cmbbx_name.Name = $"cmbbx_name_{index}"; cmbbx_name.Size = new Size(420, 30); cmbbx_name.Location = new Point(lastItem.name.Location.X, lastItem.name.Location.Y + spaceBetween); cmbbx_name.DropDownStyle = ComboBoxStyle.DropDownList; cmbbx_name.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(38)))), ((int)(((byte)(66)))), ((int)(((byte)(117))))); cmbbx_name.ForeColor = Color.White; cmbbx_name.Font = new Font("Microsoft Sans Serif", 12F); cmbbx_name.SelectedIndexChanged += new System.EventHandler(event_SelectedIndexChanged); Controls.Add(cmbbx_name); foreach (var item in items) { cmbbx_name.Items.Add(item.Name); } // Dynamic ComboBox for Color ComboBox cmbbx_color = new ComboBox(); cmbbx_color.Name = $"cmbbx_color_{index}"; cmbbx_color.Size = new Size(125, 30); cmbbx_color.Location = new Point(lastItem.color.Location.X, lastItem.color.Location.Y + spaceBetween); cmbbx_color.DropDownStyle = ComboBoxStyle.DropDownList; cmbbx_color.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(38)))), ((int)(((byte)(66)))), ((int)(((byte)(117))))); cmbbx_color.ForeColor = Color.White; cmbbx_color.Font = new Font("Microsoft Sans Serif", 12F); Controls.Add(cmbbx_color); // Dynamic ComboBox for Size ComboBox cmbbx_size = new ComboBox(); cmbbx_size.Name = $"cmbbx_size_{index}"; cmbbx_size.Size = new Size(125, 30); cmbbx_size.Location = new Point(lastItem.size.Location.X, lastItem.size.Location.Y + spaceBetween); cmbbx_size.DropDownStyle = ComboBoxStyle.DropDownList; cmbbx_size.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(38)))), ((int)(((byte)(66)))), ((int)(((byte)(117))))); cmbbx_size.ForeColor = Color.White; cmbbx_size.Font = new Font("Microsoft Sans Serif", 12F); Controls.Add(cmbbx_size); foreach (var item in sizes) { cmbbx_size.Items.Add(item); } cmbbx_size.SelectedIndex = 0; // Dynamic Button for Remove Button btn = new Button(); btn.Name = $"btn_{index}"; btn.Size = new Size(button4.Size.Width, button4.Size.Height); btn.Location = new Point(lastItem.remove.Location.X, lastItem.remove.Location.Y + spaceBetween); btn.BackColor = System.Drawing.Color.FromArgb(35, 113, 181); btn.Font = new Font("Microsoft Sans Serif", 12F); btn.ForeColor = Color.White; btn.Text = button4.Text; btn.FlatStyle = FlatStyle.Popup; btn.Click += new System.EventHandler(remove_Click); Controls.Add(btn); button3.Location = new Point(button3.Location.X, button3.Location.Y + spaceBetween); DynamicControls dynprod = new DynamicControls { image = pctbx, name = cmbbx_name, color = cmbbx_color, size = cmbbx_size, remove = btn }; dyncontrol.Add(dynprod); } else { MessageBox.Show("Nie mozna dodać więcej niż 10 przedmiotów", "Komunikat", MessageBoxButtons.OK); } }