在两个字体样式多变延迟环 [英] delay ring between two font style changing
本文介绍了在两个字体样式多变延迟环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜
我想改变控件的字体样式,很短的时间。例如2 secounds。我不喜欢:
Hi
I want to change font style of a control , for a short time. for example 2 secounds. I do like :
label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Bold);
for(int i=0,i<4000000,i++);
label1.Font = new Font(label1.Font, label1.Font.Style | FontStyle.Regular);
,但它不工作。有什么问题?
but it doesn't work. what is the problem?
推荐答案
怎么样这个扩展功能?
public static class LabelExtensions
{
public static Label BlinkText(this Label label, int duration)
{
Timer timer = new Timer();
timer.Interval = duration;
timer.Tick += (sender, e) =>
{
timer.Stop();
label.Font = new Font(label.Font, label.Font.Style ^ FontStyle.Bold);
};
label.Font = new Font(label.Font, label.Font.Style | FontStyle.Bold);
timer.Start();
return label;
}
}
另一个有趣的问题在我脑海,写这个扩展的时候:
<一href="http://stackoverflow.com/questions/2584009/lambdas-within-extension-methods-possible-memory-leak">Does这导致内存泄漏?
Another interesting question comes to my mind, when writing this extension:
Does it lead to a memory leak?
这篇关于在两个字体样式多变延迟环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文