You must Sign In to post a response.
  • Category: .NET

    Label visibility get false in blinking state in winform.

    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.


    public partial class Form1 : Form
    {
    static int flaggg;

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


    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...");
    this._timer.Tick += new EventHandler(_timer_Tick);
    }

    public void Appendlblmflash(string val)
    {
    if (InvokeRequired)
    {
    this.Invoke(new Action<string>(Appendlblmflash), new object[] { val });
    return;
    }
    lblmflash.Text = val;
    }
    }
  • #764281
    blinking label is mot common requirement, I have a nice snippet you can use.
    Timer timer = new Timer();
    timer.Interval = 500;
    timer.Enabled = false;

    timer.Start();

    if( messagesNum > oldMessagesNum)
    timer.Tick += new EventHandler( timer_Tick );
    else
    timer.Tick -= timer_Tick;

    void timer_Tick( object sender, EventArgs e )
    {
    if(messageLabel.BackColor == Color.Black)
    messageLabel.BackColor = Color.Red;
    else
    messageLabel.BackColor = Color.Black;
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764284
    what is messageNum and oldmessageNum

  • #764286
    when are you getting this message?

  • #764288
    messagesNum and oldMessagesNum are just counters you can comment that 'IF' condition and run your code
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764550
    Hi
    You can do Follwing code.

    private void timer1_Tick(object sender, EventArgs e)
    {

    Random r = new Random();
    label1.ForeColor = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));

    }

    private void label1_Click(object sender, EventArgs e)
    {
    timer1.Enabled = (!timer1.Enabled);
    }


    do not visible lable. insted you can use random class which will give a random number, with help of that you can create dynamic colors for label forecolor.


Sign In to post your comments