c#使用autoscroll = true的控件之间的间隙

时间:2014-06-06 15:04:45

标签: c# winforms scroll panel space

我有一个自动滚动设置为 true 的面板。此面板包含动态定位的其他面板。

parent.Size = new Size((f.Width - 50) + 18, f.Height - 100);
parent.Location = new Point(50, 100);
parent.MouseClick += new MouseEventHandler(parent_MouseClick);
parent.Scroll += new ScrollEventHandler(parent_Scroll);
parent.AutoScroll = true;

f.Controls.Add(parent);

...More Code...

int top = 5, left = 5;

foreach (string file in files)
    {
        Panel d = new Panel();
        d.Size = new Size(parent.Width / 5 - 10, 100);//Image Height: 70px
        d.Location = new Point(left, top);
        d.Tag = file;
        d.MouseEnter += new EventHandler(item_MouseEnter);
        d.MouseLeave += new EventHandler(item_MouseLeave);
        d.BackgroundImageLayout = ImageLayout.Stretch;

        ...More Code...

        if (left + (d.Width * 2) + 5 >= parent.Width)
        {
            top += d.Height + 5;
            left = 5;
        }
        else
            left += d.Width + 5;

        Application.OpenForms["MDC_Explorer"].Invoke(new MethodInvoker(() =>
        {
            parent.Controls.Add(d);
        }));
    }

我尝试将 parent.AutoScrollPosition.Y 添加到顶部 (顶部+ = d.Height + 5)但仍然出现差距面板之间。间隙只是垂直显示,所以我猜它与滚动值和顶部有关,但我不能在3小时后弄明白。

一些未显示的变量:

Form f; //The main Form (MDC_Explorer)
var files; //Just an array of strings

0 个答案:

没有答案