1

我想要一个标签从表单的左侧移动并停在中心

我已经能够使用

    Timer tmr = new Timer();
    int locx = 6;
    public Form1()
    {
        InitializeComponent();
        tmr.Interval = 2;
        tmr.Tick += new EventHandler(tmr_Tick);
    }

    void tmr_Tick(object sender, EventArgs e)
    {
        label1.Location = new Point(locx, 33);
        locx++;
        if (locx == 215)
        {
            tmr.Stop();
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        label1.Text = "QUICK SPARK";
        tmr.Start();
    }

我想知道是否有更好的方法来做到这一点???...任何帮助将不胜感激

4

2 回答 2

4

如果您使用的是 VS 2012 和 C# 5,您可以通过await/简单地执行此操作async

private async void Form1_Load(object sender, EventArgs e)
{
    label1.Text = "QUICK SPARK";

    for (int locx = 6; locx < 215; ++locx)
    {
        await Task.Delay(2);
        label1.Location = new Point(locx, 33);
    }
}
于 2013-07-22T18:13:28.823 回答
0

WinForm 动画库 [.Net3.5+]

一个简单的库,用于在 .Net WinForm(.Net 3.5 及更高版本)中为控件/值设置动画。基于关键帧(路径)且完全可定制。

https://falahati.github.io/WinFormAnimation/

new Animator2D(
        new Path2D(new Float2D(-100, -100), c_control.Location.ToFloat2D(), 500))
    .Play(c_control, Animator2D.KnownProperties.Location);

这会将c_control控件从 -100、-100 移动到它在 500 毫秒内处于首位的位置。

于 2016-05-19T22:59:28.250 回答