111,125
社区成员
发帖
与我相关
我的任务
分享System.Threading.Timer tmr;
private void ScrollStart()
{
panel1.Controls.Clear();
UserControl1 c;
int height;
do
{
c = new UserControl1();
panel1.Controls.Add(c);
height = SetLocationY(0);
} while (height - c.Height < panel1.Height);
var d = 5; //每次移动5像素。你可以自由调整此值
c = (UserControl1)panel1.Controls[0];
c.Dock = DockStyle.None;
tmr = new System.Threading.Timer(h =>
{
panel1.BeginInvoke((Action)delegate
{
var loc = c.Location;
var yd = loc.Y - d;
if (yd <= -c.Height)
SetLocationY(0);
else
SetLocationY(yd);
});
}, null, 200, 200);
}
private int SetLocationY(int y)
{
foreach (UserControl1 c in panel1.Controls)
{
c.Location = new Point(0, y);
y += c.Height;
}
return y;
}private void ScrollStart()
{
panel1.Controls.Clear();
UserControl1 c;
int height;
do
{
c = new UserControl1();
panel1.Controls.Add(c);
height = SetLocationY(0);
} while (height - c.Height < panel1.Height);
var d = 5; //每次移动5像素。你可以自由调整此值
c = (UserControl1)panel1.Controls[0];
c.Dock = DockStyle.None;
var tmr = new System.Threading.Timer(h =>
{
panel1.BeginInvoke((Action)delegate
{
var loc = c.Location;
var yd = loc.Y - d;
if (yd <= -c.Height)
SetLocationY(0);
else
SetLocationY(yd);
});
}, null, 200, 200);
}
private int SetLocationY(int y)
{
foreach (UserControl1 c in panel1.Controls)
{
c.Location = new Point(0, y);
y += c.Height;
}
return y;
}
你可以把这个封装为一个通用控件(因为输入模式很简单),我就懒得弄了。
private void timer1_Tick(object sender, EventArgs e)
{
label1.Location = new Point(label1.Location.X, label1.Location.Y - 10);
label2.Location = new Point(label2.Location.X, label2.Location.Y - 10);
if (label1.Location.Y < -100)
{
label1.Location = new Point(label1.Location.X, this.ClientSize.Height);
}
if (label2.Location.Y < -100)
{
label2.Location = new Point(label2.Location.X, this.ClientSize.Height);
}
}
你的这个也不难。方法很多。不过用7楼的方法貌似最简单。