H
hula
Hello
i have a problem with adding usercontrols to a panel.
I use a panel to add up to 20 usercontrols to a panel that has
autoscrol enabled.
The number of usercontrols to add, and the data that is passed to the
controls is determined upon selection of a combobox in the owner form.
Now most time everything works ok, but sometimes if the number of
controls to add is reduced (say from 10 controls to 2) my new added
controls are not shown at the right place, but somewhere to low in the
panel.
I use the .Top property to place the new control in the panel.
Here's the code:
//first remove all
for (int i = 0; i < panel.Controls.Count; i++) {
panel.Controls.RemoveAt(i);
}
//now add the new controls
int old_y=0;
Random r = new Random();
for (int i = 0; i < r.Next(10); i++) {
MyUserControl myCtrl = new MyUserControl();
panel.Controls.Add(myCtrl);
myCtrl.Top = old_y;
old_y += myCtrl.Height + 10;
}
panel.Refresh();
Can anyone tell me what i'm doing wrong?
_thanks in advance
i have a problem with adding usercontrols to a panel.
I use a panel to add up to 20 usercontrols to a panel that has
autoscrol enabled.
The number of usercontrols to add, and the data that is passed to the
controls is determined upon selection of a combobox in the owner form.
Now most time everything works ok, but sometimes if the number of
controls to add is reduced (say from 10 controls to 2) my new added
controls are not shown at the right place, but somewhere to low in the
panel.
I use the .Top property to place the new control in the panel.
Here's the code:
//first remove all
for (int i = 0; i < panel.Controls.Count; i++) {
panel.Controls.RemoveAt(i);
}
//now add the new controls
int old_y=0;
Random r = new Random();
for (int i = 0; i < r.Next(10); i++) {
MyUserControl myCtrl = new MyUserControl();
panel.Controls.Add(myCtrl);
myCtrl.Top = old_y;
old_y += myCtrl.Height + 10;
}
panel.Refresh();
Can anyone tell me what i'm doing wrong?
_thanks in advance