我正在尝试创建一个使特定文本框闪烁的类。我的代码如下:
class Blink
{
int BlinkCount = 0;
public void Text(Label Info, string Message)
{
Timer tmrBlink = new Timer();
tmrBlink.Interval = 250;
tmrBlink.Tick += new System.EventHandler(tmrBlink_Tick);
tmrBlink.Start();
Info.Text = Message;
}
private void tmrBlink_Tick(object sender, EventArgs e)
{
BlinkCount++;
if (Info.BackColor == System.Drawing.Color.Khaki)
{
Info.BackColor = System.Drawing.Color.Transparent;
}
else
{
Info.BackColor = System.Drawing.Color.Khaki;
}
if (BlinkCount == 4)
{
tmrBlink.Stop();
}
}
}
我的想法是,如果我输入以下代码,所选标签会闪烁以引起用户的注意:
Blink.Text(lblControl, "Hello World!");
答案 0 :(得分:1)
这对我来说很好......
Blink b = new Blink();
b.Text(label1, "Hello World");
class Blink
{
int BlinkCount = 0;
private Label _info;
private Timer _tmrBlink;
public void Text(Label info, string message)
{
_info = info;
_info.Text = message;
_tmrBlink = new Timer();
_tmrBlink.Interval = 250;
_tmrBlink.Tick += new System.EventHandler(tmrBlink_Tick);
_tmrBlink.Start();
}
private void tmrBlink_Tick(object sender, EventArgs e)
{
BlinkCount++;
if (_info.BackColor == System.Drawing.Color.Khaki)
{
_info.BackColor = System.Drawing.Color.Transparent;
}
else
{
_info.BackColor = System.Drawing.Color.Khaki;
}
if (BlinkCount == 4)
{
_tmrBlink.Stop();
BlinkCount = 0;
}
}
}