private void button2_Click(object sender, EventArgs e) { DialogResult dlr = MessageBox.Show("Nếu bạn muốn tạo nhanh phải xóa các trạng thái cũ !!!", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dlr == DialogResult.OK) { AmountOfMachines aom = new AmountOfMachines(); if (aom.ShowDialog() == DialogResult.OK) { foreach (Models.Machines machine in MachineController.tempmachine) { MachineController.removemachine.Add(machine); } MachineController.tempmachine.Clear(); panel1.Controls.Clear(); int nextmachinex = 20; int nextmachiney = 20; int id; try { id = MachineController.tempmachine.Min(mch => mch.machineid); } catch { id = 0; } for (int i = 0; i < aom.numofmachines; i++) { id = id - 1; string name = "ghe " + (i + 1).ToString(); Label lb = createLabel(id, name, 1, nextmachinex, nextmachiney); MachineController.AddnewMachineTemp(id, name, Convert.ToInt32((double)nextmachinex * (double)scalew), Convert.ToInt32((double)nextmachiney * (double)scaleh), 1); nextmachinex = nextmachinex + lb.Size.Width + 20; if (nextmachinex > panel1.Size.Width) { nextmachinex = 20; nextmachiney = nextmachiney + lb.Size.Height + 20; } panel1.Controls.Add(lb); } } } }