Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:27:27+00:00 2026-06-12T02:27:27+00:00

I would like to set a textbox text to blink by changing text colors

  • 0

I would like to set a textbox text to “blink” by changing text colors when a button is clicked.

I can get the text to blink how I want it to, but I want it to stop after a few blinks. I cannot figure out how to make it stop after the timer fires a few times.

Here is my code:

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

I know my problem lies with how I’m using the “timerint”, but I’m not sure where to put it, or what solution I should use…

Thank you for all your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:27:28+00:00Added an answer on June 12, 2026 at 2:27 am

    Here’s the complete code that I would use to solve your issue. It correctly stops the timer, detaches the event handler, and disposes the timer. It disables the button during the flashing, and also restores the colour of the textbox after the five flashes are complete.

    The best part is that it is purely defined within the one lambda, so no class-level variables required.

    Here it is:

            button1.Click += (s, e) =>
            {
                button1.Enabled = false;
                var counter = 0;
                var timer = new Timer()
                {
                    Interval = 500,
                    Enabled = false
                };
    
                EventHandler handler = null;
                handler = (s2, e2) =>
                {
                    if (++counter >= 5)
                    {
                        timer.Stop();
                        timer.Tick -= handler;
                        timer.Dispose();
                        textBoxInvFooter.ForeColor = SystemColors.WindowText;
                        button1.Enabled = true;
                    }
                    else
                    {
                        textBoxInvFooter.ForeColor =
                            textBoxInvFooter.ForeColor == SystemColors.GrayText
                                ? SystemColors.Highlight 
                                : SystemColors.GrayText;
                    }
                };
    
                timer.Tick += handler;
                timer.Start();
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the text out of a label. But the label
I would like the text in my textBox to be set to upper-case whenever
I would like to set a variable in bash called test_var Basically, I want
I would like to set some limits/boundaries on the amount of pixels we can
I would like to bind a textbox to show the text of the item
I would like to set the dojo-data-props of a dojo widjet but I don't
I want to set a textbox.text to a certain value if Request.QueryString['EQCN'] does not
I used the same command syntax above as in Mysql and would like set
I would like to set some values in context.xml file and access the same
I would like to set the date in a Windows batch file to 7

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.