在两个字体样式多变延迟环多变、样式、字体、两个

由网友(若善°)分享简介:喜我想改变控件的字体样式,很短的时间。例如2 secounds。我不喜欢:HiI want to change font style of a control , for a short time. for example 2 secounds. I do like :label1.Font = new Fon...

喜 我想改变控件的字体样式,很短的时间。例如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;
    }
}

另一个有趣的问题在我脑海,写这个扩展的时候: Does这导致内存泄漏?

Another interesting question comes to my mind, when writing this extension: Does it lead to a memory leak?

阅读全文

相关推荐

最新文章