Setting text in textbox through another class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fantasyland
    New Member
    • May 2009
    • 1

    Setting text in textbox through another class

    Hi,

    I am spawning a thread from Form1 which has a worker method in anther class(Class1). At the end of the worker method I want to set the text of a Text Box in the Form1 as the result of the computation of the worker method. Writing "TextBox1.T ext = string" in worker method of Class1 doesnt work although the string has the right value in it.
    Can someone please explain how to do this in simple steps ?

    Thanks
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    I would actually expect you to get an Exception to be honest attempting to do that, telling you that you can't update it because the thread doesn't own the textbox...

    I don't have time to write out a full answer.. take a look at:


    under the 'Updating Interface from Processing Thread' title. It's just a little site I setup for reference so it's not very detailed but if you use that layout to update your textbox then I imagine it'll work.

    Comment

    • Maidenz08
      New Member
      • Sep 2007
      • 31

      #3
      Why dont you try using the properties to do this. Set the value of the property in your class, Come back to your form and assign the value to the textbox from your form.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Better read about and use a BackgroundWorke r for your task.

        Comment

        Working...