The scrollable combo box causing problems

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.

+6
c # winforms compact-framework
source share
3 answers

This seems like a problem specific to the devices you are using. I cannot reproduce this behavior at all. Have you tried setting the Dock Panel property? What about other properties that affect scroll behavior (AutoScrollMargin, AutoScrollMinSize, AutoScrollPosition)? I would also play with the panel size and possibly use the System.Windows.Forms.Screen class to determine it automatically based on the device.

0
source share

Try setting auto-scroll to false and usually try using scrollbars.

Alternatively, if you cannot find another reasonable solution, it will be possible to handle scroll / resize events and manually resize / move controls (exactly what the anchor does). Although it would be very unpleasant, get rid of any problems that you may have.

0
source share

I was also able to test the Windows CE device under Visual Studio 2005.Net CF 2.0, since we also have things that use outdated equipment. I have not got problems. Could there be a problem with the version of Windows CE on the device that is causing the problem? What device is used (for example: Manufacturer?). I even created a completely new project of a single form, so no other changes to your code are affected.

Does the behavior work during debugging, runtime, or both?

0
source share

All Articles