[RESOLVED] Whats the deal with Labels and Timers?
Hey mangs, I have a timer and in that timer I am trying to make a label visible and change its text. But for some reason the label refuses to be made visible or change its text.
However, I also have a progress bar that I make visible and update in the timer and that works just fine.
So what's the deal with labels?
Thanks!
VS2005:wave:
Re: Whats the deal with Labels and Timers?
Hrmmm, it seems it does make the label show once the timer runs the second time....why not the first time?
Re: Whats the deal with Labels and Timers?
Code? What happens in between Ticks?
Re: Whats the deal with Labels and Timers?
Ok it apears it is not the timers fault after all. It is any kind of loop that is the problem. I have a form that has a button, a label and a progress bar....the default setting on each control are left at default, eveything is set in the code.
Watch how when you click the button the progress bar shows and runs immediately, but the label doesnt appear until the loop that is incrimenting the progress bar is finished.
The strange part is the label is called to be visible before the loop even starts. And even if you put the label1.Visible=true in the LOOP it still wont show up! I just don't get it.
Here is the sample code
PHP Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Visible = false;
progressBar1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
label1.Visible = true;
label1.Text = "Testing";
progressBar1.Value = 0;
progressBar1.Visible = true;
progressBar1.Maximum = 100000;
progressBar1.Minimum = 0;
progressBar1.Step = 1;
for (int i = 0; i < 100000; i++)
{
progressBar1.Increment(1);
}
}//end timer1
}
}
Re: Whats the deal with Labels and Timers?
Call the Label's Refresh method after setting its Text property. That will force it to repaint before the loop starts sucking up all the processor time.
Re: Whats the deal with Labels and Timers?
AHH! I didnt know it had a refresh method! Cool, ima try that right now.
Thanks!
Re: Whats the deal with Labels and Timers?
Yep that works!
Man, you guys rock! Thanks jm!:wave: :thumb: :bigyello: :afrog: :D :)
Made my day!