c#中的类型效果.................. [英] type effect in c# ..................

查看:66
本文介绍了c#中的类型效果..................的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在c#中模拟类型效果。



例如:



string s =如果你有学校或大学;



i想把字符串放在文本框中通过类型动画。



抱歉英语不好。

hi

how can i simulate type effect in c#.

for example :

string s ="If you have a school or university ";

i want put the string in text box by type animation.

sorry for bad english.

推荐答案

这很容易做到。



创建一个单独的线程。在这个帖子中,有一些文字。通过在循环中一次添加一个字符来修改它。在循环中添加一些 Thread.Sleep 延迟。在每次迭代时,将修改后的文本发送到要呈现的UI。这一步有点微妙,需要你的理解。



你不能从非UI线程中调用与UI相关的任何内容。相反,您需要使用 Invoke System.Windows.Threading的方法。 Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表单)。



您将在我过去的答案中找到有关其工作原理和代码示例的详细说明:

Control.Invoke()与Control.BeginInvoke() [ ^ ],

使用Treeview扫描仪和MD5的问题 [ ^ ]。



另请参阅有关线程的更多参考资料:

如何让keydown事件在不同的操作上运行vb.net中的线程 [ ^ ],

在启用禁用+多线程后控制事件未触发 [ ^ ]。



-SA
This is quite easy to do.

Create a separate thread. In this thread, have some text. Modify it by adding one character a time, in a loop. Add some Thread.Sleep delay inside loop. On each iteration, send modified text to UI to be presented. This step is a bit delicate and needs your understanding.

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


这篇关于c#中的类型效果..................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆