我想知道是否有一种方法可以为表单上显示的文本添加一种动画。
当我想到这一点时,我的想法有点类似于您可以在 PowerPoint 中对文本执行的操作(即类似打字机的动画,其中一次键入一个文本,整个文本框显示为某些效果等),我只是想了解使用 Windows 窗体可以做什么。
目前我正在使用文本框来显示有关我的表单应用程序的信息,但事后看来,我意识到标签也同样有效。
编辑:结果我毕竟使用了标签,由于缺少更好的描述,我只是给它取了一个内部带有“文本框”的名称。
最佳答案
public partial class Form1 : Form
{
int _charIndex = 0;
string _text = "Hello World!!";
public Form1()
{
InitializeComponent();
}
private void button_TypewriteText_Click(object sender, EventArgs e)
{
_charIndex = 0;
label1.Text = string.Empty;
Thread t = new Thread(new ThreadStart(this.TypewriteText));
t.Start();
}
private void TypewriteText()
{
while (_charIndex < _text.Length)
{
Thread.Sleep(500);
label1.Invoke(new Action(() =>
{
label1.Text += _text[_charIndex];
}));
_charIndex++;
}
}
}
关于c# - Windows 窗体中的文本动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12390239/