-3

I am trying to create a class that makes a particular textbox blink. My code is below:

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();
        }
    }
}

The idea is, if I type the following code, the selected label would blink to draw user's attention:

Blink.Text(lblControl, "Hello World!"); 
Keylee
  • 713
  • 1
  • 5
  • 11

1 Answers1

1

This works fine for me...

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;
        }
    }
}
  • You should explain what changes you have made that fixed the issue. If this is just a comment explaining that it works as written to you then that should be a comment and not an answer – Sayse Feb 26 '15 at 09:13
  • Oh, I didnt declare the controls at the top. Thanks, you guys are fast! – Keylee Feb 26 '15 at 09:14