动态面板元素添加和滚动条 [英] Dynamic panel element adding and scrollbars

查看:991
本文介绍了动态面板元素添加和滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于动态面板元素添加和滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆