I have a panel with AutoScroll set to true . In it, I programmatically add ComboBox controls. If I add enough controls to exceed the visible panel size, a scroll bar will appear (so far so good). However, if I open one of the lists with a list at the bottom of the viewport, the combo list does not display properly, and the scrollable area seems to expand. This leads to the fact that all the controls are โpulled outโ to the new bottom of the panel with some new free space at the top. If I continue to click on the drop-down menu at the bottom of the panel, the scrollable area will continue to expand indefinitely. I bind the controls left, right, and up, so I donโt think that this is about binding. Is there something obvious that could be causing this?
Update: it looks like the problem is that the controls are binding to the right. If I donโt get attached to the right, I donโt get strange behavior. However, without proper pinning, control is disabled by the scroll bar.
Here is a simplified test case that I built that shows the problem:
public Form1() { InitializeComponent(); Panel panel = new Panel(); panel.Size = new Size(80, 200); panel.AutoScroll = true; for (int i = 0; i < 10; ++i) { ComboBox cb = new ComboBox(); cb.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; cb.Items.Add("Option 1"); cb.Items.Add("Option 2"); cb.Items.Add("Option 3"); cb.Items.Add("Option 4"); cb.Location = new Point(0, i * 24); panel.Controls.Add(cb); } Controls.Add(panel); }
If you scroll to the bottom of the panel and tap next to the footnotes, you will notice strange behavior.
Dennis
source share