我想通过单击按钮时更改文本颜色来将文本框文本设置为“闪烁”。
我可以让文本按照我想要的方式闪烁,但我希望它在闪烁几次后停止。我不知道如何在计时器触发几次后让它停止。
这是我的代码:
public Form1()
{
InitializeComponent();
Timer timer = new Timer();
timer.Interval = 500;
timer.Enabled = false;
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
if (timerint == 5)
timer.Stop();
}
private void timer_Tick(object sender, EventArgs e)
{
timerint += 1;
if (textBoxInvFooter.ForeColor == SystemColors.GrayText)
textBoxInvFooter.ForeColor = SystemColors.Highlight;
else
textBoxInvFooter.ForeColor = SystemColors.GrayText;
}
我知道我的问题在于如何使用“timerint”,但我不确定将它放在哪里,或者我应该使用什么解决方案......
谢谢你的帮助!
您只需将计时器检查放入 Tick 处理程序中即可。您可以访问Timer
对象通过使用sender
处理程序的参数。
private void timer_Tick(object sender, EventArgs e)
{
// ...
timerint += 1;
if (timerint == 5)
{
((Timer)sender).Stop();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)