This question already has an answer here:
I want to place controls within a Form, and I have done so as following to programatically create new controls:
ListBox lb = new ListBox();
lb.Items.Add("Element One");
lb.Items.Add("Element Two");
lb.Items.Add("Element Two");
Button b1 = new Button();
b1.Text = "OK";
b1.DialogResult = DialogResult.OK;
Button b2 = new Button();
b2.Text = "Cancel";
b2.DialogResult = DialogResult.Cancel;
b2.DialogResult = DialogResult.Cancel;
Form f = new Form();
f.Controls.Add(b1);
f.Controls.Add(b2);
f.Controls.Add(lb);
f.ShowDialog();
b2.DialogResult = DialogResult.Cancel;
Form f = new Form();
f.Controls.Add(b1);
f.Controls.Add(b2);
f.Controls.Add(lb);
f.ShowDialog();
Not the most interesting box, but it will do.
I want it to show me the list of three on top, and the buttons bellow the list. Instead, it seems to "drop" everything I added on top of each other into the top-left corner.
How do I specify where my controls are placed within the Form?
Aucun commentaire:
Enregistrer un commentaire