Dozd

Dozd

  • NA
  • 65
  • 0

Update UI begginer question

Sep 17 2010 5:00 PM

Hi, I study threads (and timers) and I have question about UI updating. So I want to set label text property after some work method called  in timer tick event. After starting Timer will be execute something in method call newtext. My idea is to pass that value in user interface exactly in label1.Text. I read a lot of articles but not success, so decide to try very simple situation for learning purpose.

Here is code in user interface:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace UI_update

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

    

 

        private void button1_Click(object sender, EventArgs e)

        {

            Class1 c1 = new Class1();

          

            c1.startT();

         

 

        }

--------------------------------------------------

Here is code in class:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using System.Threading;

using System.Windows.Forms;

 

namespace UI_update

{

    class Class1

    {

        System.Windows.Forms.Timer T = new System.Windows.Forms.Timer();

 

 

        public string word;

     

      

        public void startT()

        {

 

          T.Start();

           T.Tick +=new EventHandler(T_Tick);

          

        }

 

        public void T_Tick(object sender, EventArgs e)

        {

            this.newtext();

           

       

        }

 

 

 

        public void newtext()

        {

 

   

            word = "Something";

     

        }

 

      

 

    }

}

Thanks for understanding


Answers (4)