.net c++ - how do i change labels text?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: .net c++ - how do i change labels text?

  1. #1
    Join Date
    May 2011
    Posts
    5

    .net c++ - how do i change labels text?

    Hi! I know this is riddiculous, but i cant change text on my labels. Im using VS 2010 .NET C++, and simply using label1->Text = L"abcd"; gives me nothing. How do i change text under that label in that freakin language?

  2. #2
    Join Date
    May 2011
    Posts
    5

    Re: .net c++ - how do i change labels text?

    Anyone? I've just discovered, that if i put a button on my form, and onclick() i put this->label1->Text = L"abcd"; it accually works. But i want it to work within my backgroundworker. Is that possible?

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,591

    Re: .net c++ - how do i change labels text?

    Quote Originally Posted by ojek View Post
    Anyone?
    Do you really think it's appropriate to bump after as little as 39 minutes!?

    I've just discovered, that if i put a button on my form, and onclick() i put this->label1->Text = L"abcd"; it accually works. But i want it to work within my backgroundworker. Is that possible?
    Well, that perfectly explains why this seemingly simple operation failed. The simple and fundamental rule is: Never do GUI manipulations directly from a worker thread! The way out of this dilemma is to either call the label's property set accessor in a thread-safe way (http://msdn.microsoft.com/en-us/library/ms171728.aspx is probably a good place to start reading about that) or to have the BackgroundWorker class do the inter-thread communication for you the right way by "abusing" BackgroundWorker's progress reporting feature to some extent.

    An example of doing the latter can be found in http://www.codeguru.com/forum/showthread.php?p=2012459. Note that the way I did it there actually is more convoluted than it basically needs to be due to accomodating to the given scenario. Also note that the code in that thread is no example how to write code the right way, rather of getting the best out of the situation once the damage is done...

    And if your intention behind changing the label's text even is to report some sort of progress, this isn't even an abuse. Actually, what I do in the code posted in the thread I linked to above is some sort of progress report as well, it's just not reported in terms of "percent completed" which is strongly suggested by the design of the BackgroundWorker's progress reporting interface.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    May 2011
    Posts
    5

    Re: .net c++ - how do i change labels text?

    Oh. Thank you Eri, that solved my problem. :-)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center