arg*_*rgh 4 c# scroll position winforms
问题描述:
在你回答之前:
1)是的,事情需要这样
2)以下代码示例:
public partial class Form1 : Form
{
List<UserControl2> list;
public Form1()
{
InitializeComponent();
list = new List<UserControl2>();
for (int i = 0; i < 20; i++)
{
UserControl2 c = new UserControl2();
list.Add(c);
}
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (UserControl2 c in list)
userControl11.Controls.Add(c);
}
private void button1_Click(object sender, EventArgs e)
{
int y = 0;
foreach (UserControl2 c in list)
{
c.Location = new Point(0, y);
y += c.Height;
}
}
}
Run Code Online (Sandbox Code Playgroud)
因为Location给出了控件左上角相对于其容器左上角的坐标.因此,当您向下滚动时,位置将会更改.
以下是如何修复它:
private void button1_Click(object sender, EventArgs e)
{
int y = list[0].Location.Y;
foreach (UserControl2 c in list)
{
c.Location = new Point(0, y);
y += c.Height;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3385 次 |
| 最近记录: |