Solved

Refresh Winforms control c#

Posted on 2011-02-17
3
2,674 Views
Last Modified: 2013-12-17
Hi

A little new to c# winforms programming

I have a form that has a Text Control that I want to display some text then wait clear it out and loop to the next values

I have something like this

          do
            {

             txtList.Text = "A bunch of text";
   .....
   .....  // More text is displayed
   .....
                System.Threading.Thread.Sleep(10000); // wait then clear text
                txtList.Text = "";

           } while (iPos > 0);  


Everything works fine except the displaying. It seems to wait until everything is done. How can I get the textbox to refresh while the data is building then do the next iteration of text display?

Thanks
Chuck
0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:TheMozz
ID: 34917436
You may consider using a Timer control instead. You could use the Timer_Tick event to do data processing and updating on your form.

What are you displaying in that text box as the loop executes?
0
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 100 total points
ID: 34917530
Adding a Timer and using the Timer_Tick function the form is drawn
The Timer then ticks in a other thread and will change the values in your form (thread) and so the form will be redrawn.

So indeed, use a Timer and put you're text-swapping-Changes in the Timer_tick event.
0
 
LVL 8

Accepted Solution

by:
TheMozz earned 400 total points
ID: 34917536
One other quick thing, as you add text to the textbox, you'll need to tell the textbox to refresh it's display:

this.txtList.Refresh();

And then call Application.DoEvents() to allow the operating system to do the drawing of the screen. That is why it waits to refresh the display.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question