动态面板元素添加和滚动条滚动条、面板、元素、动态

由网友((独自一人))分享简介:我写了一个函数动态地添加元素的面板。I wrote a function to dynamically add elements to the "Panel".public int State; public Point Point = new Point(0, 0);public void Di...

我写了一个函数动态地添加元素的面板。

I wrote a function to dynamically add elements to the "Panel".

public int State;        
public Point Point = new Point(0, 0);
public void DialogAdd(string message, string author)
        {
            var d = new DialogMessage();
            if(State == 0)
            {
                d.BackColor = Color.FromArgb(255, 237, 241, 245);
                State = 1;
            }
            else
            {
                State = 0;
            }


            d.Controls["name"].Text = author;
            d.Location = new Point(0, Point.Y);
            d.Controls["msg"].Text = message;
            Point.Y += d.Size.Height;
            Controls["panel1"].Controls.Add(d);

        }

DialogMessage是用户控件,是富人的所有组件属性自动调整大小=真。 这个小组已经拿到了AutoScroll属性,因此得到了滚动条。 问题是,该元素被添加以不同的方式,这取决于滚动条的位置。如果该滚动条的顶部,然后根据需要加入的所有

DialogMessage is UserControl, that haves property "AutoSize=true" on all components. This panel has got the AutoScroll property, so has got scrollbars. The problem is that the elements are added in different ways, depending on the position of the scrollbar. If the scrollbar is at the top, then all added as needed.

但如果在添加滚动条底部时,再加入项目脚麻

but if at the time of adding the scrollbar at the bottom, then add items going wrong

请告诉我,我做错了,如何解决?谢谢。遗憾的英语不好

please tell me what I'm doing wrong and how to fix it? Thank you. sorry for bad english

推荐答案

放置控件时,面板内,你必须补偿滚动位置:

When placing the controls inside the panel, you have to compensate for the scroll position:

基本上,请尝试使用这一行:

Basically, try using this line:

d.Location = new Point(0, panel1.AutoScrollPosition.Y + Point.Y);
阅读全文

相关推荐

最新文章