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 8956981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:53:11+00:00 2026-06-15T14:53:11+00:00

I have this code: namespace TuyenTk { public partial class Form1 : Form {

  • 0

I have this code:

namespace TuyenTk
{
    public partial class Form1 : Form
    {
        Form2 _form2 = new Form2("");
        public Form1()
        {
            InitializeComponent();
            _form2.Show();
            int i = 0;
            while (i < 5)
            {
                _form2.label1.Text = "" + i;
                Thread.Sleep(500);
                i++;
            }
        }
    }

    public class Form2 : Form
    {
        public System.Windows.Forms.Label label1;
        public System.ComponentModel.Container components = null;

        public Form2()
        {
            InitializeComponent();
        }
        private void InitializeComponent(string t)
        {
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(5, 5);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(290, 100);
            this.label1.TabIndex = 0;
            this.label1.Text = t;
            // 
            // Form2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(300, 100);
            this.ControlBox = false;
            this.Controls.Add(this.label1);
            this.Name = "Form2";
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.ShowInTaskbar = false;
            this.ResumeLayout(false);    
        }
    }
}

when Form1 run, it show the Form2, but the Form2.label1 background is white, and have no text.
After 2.5 seconds, Form2.label1.Text = 4. So the value 0, 1, 2, 3 of i dont appear. How I can fix it? Thank you very much.

  • 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-15T14:53:13+00:00Added an answer on June 15, 2026 at 2:53 pm

    What you want to do (periodically update label) is achieved by usage of Timer component (you can drag it from ToolBox and place on your form).

    public partial class Form1 : Form
    {
       Form2 _form2 = new Form2("");
       Timer _timer;
       int _counter;
    
       public Form1()
       {
           InitializeComponent();          
           _form2.Show();
    
           if (components == null)
               components = new System.ComponentModel.Container();
           _timer = new Timer(components); // required for correct disposing
    
           _timer.Interval = 500;
           _timer.Tick += timer_Tick;
           _timer.Start();
       }
    
       private void timer_Tick(object sender, EventArgs e)
       {
           if (_counter < 5)
           {
              _form2.label1.Text = _counter.ToString();
              _counter++;
              return;
           }
    
           _timer.Stop();
       }
    

    Also creating public controls on other forms is not very good idea – if you really need to update some value on form2, then its better to declare public method/property in Form2 class, which will update label:

    public partial class Form2 : Form
    {
         public int Value
         {             
             set { label1.Text = value.ToString(); }
         }
    }
    

    Also consider to move timer to Form2 (let this form update itself).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code behind: CustomUserControl.xaml.cs namespace MyProject { public partial class CustomUserControl<T> :
I have this code: namespace Some\Different\Name; try { $reflect = new ReflectionClass($class); X: $instance
I have this code: #include <iostream> using namespace std; class FooA { public: virtual
I have this code #include <iostream> using namespace std; class Test{ public: int a;
I have this code; using System; namespace Rapido { class Constants { public static
i have this code snippet #include <iostream> using namespace std; class Polygon { public:
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
I'm very new to namespace and global variables. I presently have this code: $('#formats1').hover(function()
I have this code namespace MSL{ template <typename T> class TListNode; template <typename T>
I have this code: using System; using System.Diagnostics.Contracts; namespace TestCodeContracts { class Program {

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.