在Windows窗体C#的文字动画 [英] Text animation on a windows form c#
问题描述
我在想,如果有一个窗体上的文字显示添加了一种动画的方式。
我有什么考虑时,我还以为这是一种类似于你可以在PowerPoint中的文本做什么(即一台打字机般的动画,其中文本输入一次,把整个文本框出现了一定的效果等),我只是希望找出你可以使用Windows窗体做什么。
目前我使用一个文本框来显示我的窗体应用程序的信息,虽然事后我意识到标签会一直工作一样好。
任何及所有建议都欢迎。 = D
编辑:原来我是用标签毕竟,我只是给它一个名字与文本框里面缺乏一种。更好的描述
公共部分Form1类:表格
{
INT _charIndex = 0;
串_text =的Hello World!;
公共Form1中()
{
的InitializeComponent();
}
私人无效button_TypewriteText_Click(对象发件人,EventArgs五)
{
_charIndex = 0;
label1.Text =的String.Empty;
线程t =新主题(新的ThreadStart(this.TypewriteText));
t.Start();
}
私人无效TypewriteText()
{
,而(_charIndex< _text.Length)
{
Thread.sleep代码(500 );
label1.Invoke(新动作(()=>
{
label1.Text + = _text [_charIndex];
}));
_charIndex ++;
}
}
}
I was wondering if there was a way of adding a sort of animation to text displayed on a form.
What I had in mind when I thought of this was kind of similar to what you can do with text in Powerpoint (i.e. a typewriter-like animation where the text is typed one at a time, have the whole textbox appear with a certain effect etc), I'm just looking to find out what you can do using windows forms.
Currently I'm using a textbox to display information on my form application, though in hindsight I realise labels would've worked just as well.
Any and all suggestions are welcome. =D
EDIT: Turns out I was using labels after all, I just gave it a name with 'textbox' inside for lack of a better description.
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++;
}
}
}
这篇关于在Windows窗体C#的文字动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!