Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created one blinking label by changing its forecolor and visibily properties and timer control. It works nice for the first tick event call but after more than one call the label visibility gets continuous false value for some call and its time interval also gets reduced and it blinking fast. where is the problem i cant detect.
please give me solution and let me know where is the problem.

thanks ,
here is my code to understand my situation better.

C#
public partial class Form1 : Form
    { 
 protected System.Windows.Forms.Timer _timer;
       static int flaggg;

        private void Form1_Load(object sender, EventArgs e)
        {
           _timer = new System.Windows.Forms.Timer();
           this._timer.Interval = 700;
           this._timer.Start(); 
           this._timer.Tick += new EventHandler(_timer_Tick);
        }


public void _timer_Tick(object sender, EventArgs e)
        {
            this.lblmflash.Visible = !this.lblmflash.Visible;
           // this.lblmflash.Visible = true;
            lblmflash.ForeColor = Color.DarkGreen;
           
            if (flaggg == 1)
            {
                Appendlblmflash("Process completed, Send Another Indent");
                flaggg = 0;
            }
            //this.lblmflash.Visible = false;
        }

  public void GetData() // to run server //
        {
          string res = System.Text.Encoding.ASCII.GetString(temp);

          switch (res.Substring(0, 1))
          {
            case "O":
            if (res.StartsWith("OUTPROCESS"))
            {
                flaggg = 1;
            }
            break;
          }
        }

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Appendlblmflash("Indent in process! Please wait...");
            
        }

 public void Appendlblmflash(string val)
        {
            if (InvokeRequired)
            {
              this.Invoke(new Action<string>(Appendlblmflash), new object[] { val });
              return;
            }
            lblmflash.Text = val;
        }
}
Posted
Updated 26-Jan-16 20:12pm
v4
Comments
Sergey Alexandrovich Kryukov 26-Jan-16 23:35pm    
There are so many so apparent problems in code so I don't even know where to start. I would not use any part of it, rewrite from scratch.

What timer type is it? Why flag is integer, not Boolean? As I understand, you need to keep blinking for a while and top blinking. Is that right? But then, what defines the moment of time to stop blinking? It should not be the counter of flagg...

What else? Hard-coded "O", "OUTPROCESS", etc., — this is bad.

Perhaps you should start with the explanation: what do you really want to achieve, ultimately?

—SA
Member 11543226 27-Jan-16 0:11am    
I explain you in details,
i used system.windows.forms.timer ,
"OUTPROCESS" is hard coded becoz this application is server and when server receives this string from client the flag is set to 1 and need to change label text.
i need blinking label to get user attention becoz if client is busy in doing some task
user(server) is not allowed to send data. thats why i did this type of coding becoz this exactly is my requirement
dan!sh 27-Jan-16 0:48am    
Let me try to understand this. You have a windows form. User does some action and it triggers a long process (on a separate thread?). While this process is going on, you don't want user to trigger another process?

1 solution

I would suggest the following to solve the Problem :
- at 1st you create your own customized Label (which derives from Label) which has additional Properties like SetBlink as boolean and BlinkColor as Color.
- this new Label integrates the Timer in it
- you should not work with the Visibility to make it blinking - better you set a new Color-Value (BlinkColor) to the ForeColor (or BackColor or both if you prefer). For this you have to override the ForeColor-Property to redirect it's value to an internal variable.
- now you could switch inside the Timer-Method between those both Colors for the ForeColor if SetBlink is true (else return to the saved ForeColor-Value).

If this could be a Solution for you I would give you (if necessary) Code-Examples how to realise that.
 
Share this answer
 
Comments
dan!sh 27-Jan-16 1:11am    
Why not use visible property?
Ralf Meier 27-Jan-16 5:04am    
Because I don't like that. In this case the different Properties are no longer indepent. What happen if you (the user of the control) decide, that you want to make it invisible (with activated Blinking) ?
dan!sh 27-Jan-16 5:18am    
hint: new public bool Visible.

P.S. I have something like this done already.
Ralf Meier 27-Jan-16 5:25am    
OK ... you are right. If I override the Visible-Property too I could work with it nearly in the same way as with the Color-Property.
I think it's the turn of the OP to decide how to go further ...
Member 11543226 27-Jan-16 2:15am    
Get this working by calling tick event just after starting of timer in form_load

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900