Results 1 to 7 of 7

Thread: [RESOLVED] Whats the deal with Labels and Timers?

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Resolved [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
    Last edited by Arc; Aug 17th, 2007 at 12:17 AM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    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?
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Whats the deal with Labels and Timers?

    Code? What happens in between Ticks?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    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 senderEventArgs e)
            {
                
    label1.Visible false;
                
    progressBar1.Visible false;
            }

            private 
    void button1_Click(object senderEventArgs 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 0100000i++)
                {
                    
    progressBar1.Increment(1);
                }
            }
    //end timer1
        
    }

    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Whats the deal with Labels and Timers?

    AHH! I didnt know it had a refresh method! Cool, ima try that right now.

    Thanks!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Whats the deal with Labels and Timers?

    Yep that works!

    Man, you guys rock! Thanks jm!

    Made my day!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width