这是制作';动画';文本

本文关键字:动画 文本 | 更新日期: 2023-09-27 17:57:47

我正试图在我的应用程序中添加一个"正在加载…"文本(或其他类似文本)。但这是最简单的&最短的方法?

我现在正在使用这个代码:

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";
}

这是制作';动画';文本

怎么样:

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

进近的较短路径

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

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

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

我建议类似的东西:

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

我不知道你使用的是哪种技术,但在WPF、Silverlight、WP、Win8等中,你应该使用Storyboards

情节提要概述:

本主题介绍如何使用情节提要对象来组织和应用动画。它描述了如何交互式操作情节提要对象,并描述了间接属性目标语法。

示例:

<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,您可以在此处找到答案。

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