开发者

Combo box in a scrollable panel causing problems

开发者 https://www.devze.com 2023-01-24 05:47 出处:网络
I have a panel with AutoScroll set to true.In it, I am programmatically adding ComboBox controls.If I add enough controls to exceed the viewable size of the panel a scroll bar appears (so far so good)

I have a panel with AutoScroll set to true. In it, I am programmatically adding ComboBox controls. If I add enough controls to exceed the viewable size of the panel a scroll bar appears (so far so good). However, if I open one of the combo boxes near the bottom of the viewable area the combo list isn't properly displayed and the scrollable area seems to be expanded. This results in all of the controls being "pulled" to the new bottom of the panel with some new blank space at the top. If I continue to tap on the drop down at the bottom of the panel the scrollable area will continue to expand indefinitely. I'm anchoring the controls to the left, right and top so I don't think anchoring is involved. Is there something obvious that could be causing this?

Update: It looks like the problem lies with anchoring the controls to the right. If I don't anchor to the right then I don't get the strange behavior. However, without right anchoring the contr开发者_Go百科ol gets cut off by the scroll bar.

Here's a simplified test case I built that shows the issue:

    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 the bottom of the panel and tap on the combo boxes near the bottom you'll notice the strange behavior.


This seems to be a problem specific to the devices you are using. I can't reproduce this behavior at all. Have you tried setting the Dock property of the Panel? How about the other properties that affect scrolling behavior (AutoScrollMargin, AutoScrollMinSize, AutoScrollPosition)? I'd also play with the size of the panel, and maybe use the System.Windows.Forms.Screen class to determine it automatically based on the device.


Try setting autoscroll to false and try using scroll bars normally.

Alternatively, if you are unable to find another reasonable solution, it would be possible to handle the scroll/resize events and manually resize/move your controls (Exactly what anchor does) While this would be quite annoying to do, it would get rid of any problems you may be having.


I too was able to test against a device of Windows CE, under Visual Studio 2005, .Net CF 2.0 as we too have stuff using older equipment too. I have no problems. Might it be any issue of the Windows CE version on the device that is causing the issue? What device is being used (ie: Manufacturer?). I even created a brand new project of the single form, so no other things going on to alter / influence your code.

Does the behavior work while debugging, run-time, or both?

0

精彩评论

暂无评论...
验证码 换一张
取 消