private void CreateControlElements(EditFormTable eft) { int X = 10; int Y = 30; int maxwidth = 0; bool havecombobox = false; for (int i = 0; i < eft.Fields.Count; i++) { Label label = new Label(); label.Text = eft.Fields[i].FieldCaption; //label.Width = eft.Fields[i].FieldCaption.Length * 10; maxwidth = (maxwidth < label.Width? label.Width : maxwidth); label.Location = new Point(X, Y); panel1.Controls.Add(label); Y += 25; } Y = 30; for (int i = 0; i < eft.Fields.Count; i++) { if (eft.Fields[i].HaveLink) { havecombobox = true; ComboBox comboBox = new ComboBox(); comboBox.Tag = eft.Fields[i]; comboBox.Name = "comboBox" + i; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.Width = 200; comboBox.Location = new Point(maxwidth + X, Y); UpdateComboBox(comboBox, eft.Fields[i]); panel1.Controls.Add(comboBox); CreatedControls.Add(comboBox); Button buttonf = new Button(); buttonf.Cursor = Cursors.Hand; //button buttonf.Text = "Добавить запись"; buttonf.Width = 100; buttonf.Location = new Point(comboBox.Width + comboBox.Location.X + 5, Y); buttonf.Click += delegate(object sender, EventArgs arg) { EditForm ef = new EditForm((comboBox.Tag as FieldForm).TableField, _database); ef.FormClosing += Ef_FormClosing; ef.Tag = comboBox; ef.ShowDialog(); }; panel1.Controls.Add(buttonf); Button buttong = new Button(); buttong.Cursor = Cursors.Hand; //button buttong.Text = "Изменить запись"; buttong.Width = 100; buttong.Location = new Point(buttonf.Width + buttonf.Location.X + 5, Y); buttong.Click += delegate(object sender, EventArgs arg) { if (comboBox.SelectedIndex == -1) { MessageBox.Show("Необходимо выбрать запись!"); return; } EditForm ef = new EditForm((comboBox.Tag as FieldForm).TableField, _database, (comboBox.Tag as FieldForm).IDs[comboBox.SelectedIndex]); ef.FormClosing += Ef_FormClosing; ef.Tag = comboBox; ef.ShowDialog(); }; panel1.Controls.Add(buttong); } else if (eft.Fields[i].Date) { DateTimePicker dateTimePicker = new DateTimePicker(); dateTimePicker.Tag = eft.Fields[i]; dateTimePicker.CustomFormat = "yyyy-MMM-dd"; dateTimePicker.Format = DateTimePickerFormat.Custom; dateTimePicker.Name = "dateTimePicker" + i; dateTimePicker.Width = 200; dateTimePicker.Location = new Point(maxwidth + X, Y); panel1.Controls.Add(dateTimePicker); CreatedControls.Add(dateTimePicker); } else if (eft.Fields[i].Check) { CheckBox checkBox = new CheckBox(); checkBox.Tag = eft.Fields[i]; checkBox.Name = "checkBox" + i; checkBox.Width = 200; checkBox.Location = new Point(maxwidth + X, Y); panel1.Controls.Add(checkBox); CreatedControls.Add(checkBox); } else { TextBox textBox = new TextBox(); textBox.Tag = eft.Fields[i]; if (eft.Fields[i].CheckInt) { textBox.TextChanged += delegate(object sender, EventArgs arg) { if (textBox.Text.Length == 0) { return; } if (!Char.IsDigit(textBox.Text[textBox.Text.Length - 1])) { MessageBox.Show("Должны вводиться числа!", "Ошибка!", MessageBoxButtons.OK); textBox.Text = ""; return; } } } ; textBox.Name = "textBox" + i; textBox.Width = 200; textBox.Location = new Point(maxwidth + X, Y); panel1.Controls.Add(textBox); CreatedControls.Add(textBox); } Y += 25; } panel1.Width = maxwidth + 240 + (havecombobox ? 200 : 0); panel1.Height = Y + 40; //panel1.AutoSize = true; this.Width = panel1.Width + 17; this.Height = panel1.Height + 100; Button button = new Button(); button.Cursor = Cursors.Hand; button.Click += SendQuery; button.Name = "ButtonOk"; button.Text = "OK"; button.Width = 100; button.Location = new Point(panel1.Width / 2 - button.Width / 2, Y + 10); panel1.Controls.Add(button); pictureBoxHeader.Width = panel1.Width; label1.Location = new Point(pictureBoxHeader.Width / 2 - label1.Width / 2, label1.Location.Y); }