这是制作“动画片”的最简单方法吗?文本?

时间:2014-04-10 09:43:10

标签: c# winforms animation text

我试图添加" 正在加载... "我的申请中的文字(或其他此类文字)。但这是最简单的吗?最短的做法?

我现在正在使用此代码:

private void timer1_Tick(object sender, EventArgs e)
{
    if (label1.Text == "Loading")
        label1.Text = "Loading .";
    else if (label1.Text == "Loading .")
        label1.Text = "Loading . .";
    else if (label1.Text == "Loading . .")
        label1.Text = "Loading . . .";
    else if (label1.Text == "Loading . . .")
        label1.Text = "Loading";
}

5 个答案:

答案 0 :(得分:2)

怎么样:

private int numberOfPoints = 0;

private void timer1_Tick(object sender, EventArgs e)
{
   int maxPoints = 3;
   label.Text = "Loading" + new string('.', numberOfPoints);
   numberOfPoints = (numberOfPoints + 1) % (maxPoints + 1);
}

答案 1 :(得分:0)

更短的方法

private void timer1_Tick(object sender, EventArgs e)
{
   label1.Text = (label1.Text == "Loading . . .") ? "Loading" : (label1.Text + " .");
}

答案 2 :(得分:0)

我没有运行代码,但我希望你能理解。

string[] messages = {
    "loading",
    "loading .",
    "loading ..",
    "loading ..."
};

int turn = 0;

private void timer1_Tick(object sender, EventArgs e)
{
    label1.Text = messages[turn++];
    turn %= messages.Length;
}

答案 3 :(得分:0)

我建议类似的东西:

private int counter = 0;

private void timer1_Tick(object sender, EventArgs e)
{
    label1.Text = string.Format("Loading{0}", new string('.', (++counter) % 3));
}

答案 4 :(得分:-1)

我不知道您使用的技术,但在WPF,Silverlight,WP,Win8等中。您应该使用Storyboards

Storyboards Overview

  

本主题说明如何使用Storyboard对象来组织和应用动画。它描述了如何以交互方式操作Storyboard对象并描述间接属性定位语法。

示例:

<Storyboard>
   <DoubleAnimation 
     Storyboard.TargetName="MyRectangle"
     Storyboard.TargetProperty="Width"
     From="100" To="200" Duration="0:0:1" />

  <ColorAnimation 
    Storyboard.TargetName="MySolidColorBrush"
    Storyboard.TargetProperty="Color"
    From="Blue" To="Red" Duration="0:0:1" />  
</Storyboard>

对于WinForms,您可以找到答案here

  

本文旨在说明如何将动画添加到Windows窗体。第一部分将简要介绍设计Windows窗体的过程。接下来将是使用Graphics类在Form上绘图的示例。最后,本文将以代码结束,该代码既可以在.NET Framework的DOS提示符下编译,也可以使用构成Visual Studio项目的单独文件构建。