Solved

Refresh Winforms control c#

Posted on 2011-02-17
3
2,623 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:charlesbaldo
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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